使用NMFTP上传文件时,怎样先在FTP上建立相应的目录,然后把文件上传到对应的文件夹中

yykitty 2006-02-11 08:06:16
使用NMFTP上传多个文件,并且文件不都在同一个文件夹里时,怎样先在FTP上建立相应的目录,然后把文件上传到对应的文件夹中?
...全文
256 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
我不懂电脑 2006-02-15
  • 打赏
  • 举报
回复
Applies to

TNMFTP component

Declaration

procedure MakeDirectory(DirectoryName: string);

Description

The MakeDirectory method creates a directory in the current working directory on the remote FTP host.

Parameters:

The DirectoryName parameter specifies the name of the directory to create on the remote host. This can be a single directory name to be created in the current working directory, or a full directory path.

Notes:

If this command succeeds, the OnSuccess event will be called, otherwise the OnFailure event is called. In either case, cmdMakeDir is passed as the Trans_Type parameter in the event.
Leighf 2006-02-15
  • 打赏
  • 举报
回复
关注中……
yykitty 2006-02-15
  • 打赏
  • 举报
回复
to songhtao(三十年孤独):
能不能具体点?
yykitty 2006-02-15
  • 打赏
  • 举报
回复
这是我做的函数,第一次上传时没问题,第二次上传时就出错,也就是说FTP上没有这些文件夹,新建时不出错,在判断FTP上当前目录下有无该文件夹时出错。
void _fastcall TForm1::Dir2(AnsiString Path,TNMFTP *NMFTP,AnsiString filedir,AnsiString dir)
{
FILE *fp;
AnsiString FilePath;
AnsiString lp;
int ii;
TSearchRec sr;
FilePath=Path.SubString(1,Path.Length()-4);
int iAttributes = faDirectory | faArchive; // 查找 存档文件 及 文件夹
if (FindFirst(Path, iAttributes, sr) == 0) //如果有存档文件或文件夹
{
do
{
if ((sr.Attr & iAttributes) == faArchive) //如果是文件
{
nf[numf].filepath=FilePath;
nf[numf].filename=sr.Name;
nf[numf].changetime=AnsiString(GetFileTime(FilePath+"\\"+sr.Name,1));
numf++;
}
else if ((sr.Attr & iAttributes) == faDirectory &&
sr.Name != "." &&sr.Name != ".." ) //如果是文件夹
{
//判断FTP上当前目录下有无该文件夹,没有,新建,否则,跳过
num=0;
NMFTP->List();
for(int i=0;i<num;i++)
{
//找到相同的文件夹,到下一层继续找
if(sr.Name==fnode[i].nodename)
{
NMFTP->ChangeDir(sr.Name);
Dir2(ExtractFilePath(Path)+sr.Name+"\\*.*",NMFTP,filedir,dir); // 递归调用
}
}
lp=ExtractFilePath(Path).SubString(filedir.Length()+1,ExtractFilePath(Path).Length()-filedir.Length()+1);
NMFTP->ChangeDir(dir.operator +(lp));
//没找到相同的文件夹,新建
//lp=ExtractFilePath(Path).SubString(filedir.Length()+1,ExtractFilePath(Path).Length()-filedir.Length()+1);
// NMFTP->ChangeDir(dir.operator +(lp));
NMFTP->MakeDirectory(sr.Name);
NMFTP->ChangeDir(sr.Name);
Dir2(ExtractFilePath(Path)+sr.Name+"\\*.*",NMFTP,filedir,dir); // 递归调用
}
//将当前本地文件夹的路径换成FTP上相应文件夹的路径
lp=ExtractFilePath(Path).SubString(filedir.Length()+1,ExtractFilePath(Path).Length()-filedir.Length()+1);
NMFTP->ChangeDir(dir.operator +(lp));
}
while (FindNext(sr) == 0);
FindClose(sr);
}
}
//--------------------------------------------------------
void __fastcall TForm1::NMFTPBListItem(AnsiString Listing)
{
AnsiString s;
AnsiString list=Listing.SubString(Listing.LastDelimiter(" ")+1,Listing.Length()-Listing.LastDelimiter(" ")+1);
if(list!="." && list!="..")
{
//根结点下所有文件和文件夹
s=Listing.SubString(1,1);
if(s=="d")
{
fnode[num].nodename=list;
num++;
}
}
}

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧