我们有一个OpenVMS(VMS)Alpha服务器,我需要访问它才能通过FTP传输文件。问题是它不支持在启动连接时使用的FtpWebRequest
命令(ftp://192.168.xx.xx),除了FtpWebRequest之外,还有其他的FTP功能吗?使用FtpWebRequest上传文件时获取“无效的URL”
我一直在Windows和Unix环境中使用我的代码,但这是我第一次在VMS操作系统上执行它,我也可以使用命令提示符通过FTP访问服务器。
下面是我的代码:
//Initializing ftp request
ftp ftpClient = new ftp(@"ftp://192.168.xx.xx/", "username", "password");
MessageBox.Show((ftpClient.upload("FILE.TAB", @"C:\FILE.TAB")).ToString());
public ftp(string hostIP, string userName, string password)
{
host = hostIP; user = userName; pass = password;
}
public string upload(string remoteFile, string localFile)
{
try
{
/* Create an FTP Request */
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + remoteFile);
/* Log in to the FTP Server with the User Name and Password Provided */
ftpRequest.Credentials = new NetworkCredential(user, pass);
///* When in doubt, use these options */
ftpRequest.UseBinary = false;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
/* Specify the Type of FTP Request */
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
/* Establish Return Communication with the FTP Server */
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
ftpStream = ftpRequest.GetRequestStream();
/* Open a File Stream to Read the File for Upload */
FileStream localFileStream = new FileStream(localFile, FileMode.Open);
/* Buffer for the Downloaded Data */
byte[] byteBuffer = new byte[bufferSize];
int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
/* Upload the File by Sending the Buffered Data Until the Transfer is Complete */
while (bytesSent != 0)
{
ftpStream.Write(byteBuffer, 0, bytesSent);
bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
}
/* Resource Cleanup */
localFileStream.Close();
ftpStream.Close();
ftpRequest = null;
return "0";
}
catch (Exception ex) { return ex.ToString(); }
//return 1;
}
我得到上面的代码中的错误是“无效的网址......”。
而错误我收到的时候我尝试在浏览器中运行它:
但我可以连接在Windows中使用通常的cmd命令:
任何建议?
*我得到上面的代码中的错误是“无效的URL .... “*:你问题中的代码不能抛出任何东西。向我们展示引发的实际代码(可能涉及'FtpWebRequest'的代码) – 2015-03-03 08:08:01
另请参见http://stackoverflow.com/q/17306890/850848 – 2015-03-03 08:09:25
@MartinPrikryl - 您在那里,代码已更新。 – NickSharp 2015-03-03 08:53:41