【发布时间】:2017-06-17 18:12:38
【问题描述】:
我正在使用 Tamir SharpSSH 将文件从远程传输到本地,反之亦然,没有任何问题。
但是,当我尝试通过 SFTP 上传多个 XML 文件时却收到错误消息:
路径中有非法字符。
如果我尝试使用确切的文件名上传,它会毫无问题地传输文件。
每次我尝试上传两个 XML 文件时:
KDO_E2D_A21_AA769_20170124_143123.xml
KDO_E2D_A21_AA776_20170130_143010.xml
string ftpURL = "11.11.11.1";
string userName = "Aaaaaa"; //User Name of the SFTP server
string password = "hah4444"; //Password of the SFTP server
int port = 22; //Port No of the SFTP server (if any)
//The directory in SFTP server where the files will be uploaded
string ftpDirectory = "/home/A21sftp/kadoe/";
//Local directory from where the files will be uploaded
string localDirectory = "E:\\Zatpark\\*.xml";
Sftp Connection = new Sftp(ftpURL, userName, password);
Connection.Connect(port);
Connection.Put(localDirectory, ftpDirectory);
Connection.Close();
【问题讨论】:
-
E:\Zatpark\*.xml对我来说似乎不是一个有效的路径。您的 Sftp 实现是否明确允许这样的传输? (如果确实如此,我会感到惊讶)。这可能是 "illegal characters in path" 错误的原因,因为*不是有效的路径字符。顺便说一句:你应该真正决定一个单一的命名约定,即使在这个简短的代码中你使用了三个不同的。 -
如果您想在路径中使用通配符掩码并使用其他第三方库可能是一种选择,您可能需要查看此componentpro.com/sftp.net,示例如下:componentpro.com/doc/sftp/upload-files.htm