C# 获得;无效URL";使用FtpWebRequest上载文件时
我们有一个OpenVMS(VMS)Alpha服务器,我需要访问它,以便通过FTP传输文件。问题是它不支持在启动连接()时在C# 获得;无效URL";使用FtpWebRequest上载文件时,c#,ftp,ftpwebrequest,openvms,C#,Ftp,Ftpwebrequest,Openvms,我们有一个OpenVMS(VMS)Alpha服务器,我需要访问它,以便通过FTP传输文件。问题是它不支持在启动连接()时在FtpWebRequest中使用的命令,除了FtpWebRequest之外,我还可以使用其他FTP功能吗 我以前在Windows和Unix环境中使用过我的代码,但这是我第一次在VMS操作系统上使用,我还可以使用命令提示符通过FTP访问服务器 下面是我的代码: //Initializing ftp request ftp ftpClient = new ftp(@"ftp://
FtpWebRequest
中使用的命令,除了FtpWebRequest之外,我还可以使用其他FTP功能吗
我以前在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;
}
上面代码中的错误是“无效URL…”
当我尝试在浏览器上运行时,出现以下错误:
但我可以在windows中使用常用的cmd命令进行连接:
有什么建议吗???URL没有表单
ftp://192.168.xx.xx:FILE.TAB
但是
ftp://192.168.xx.xx/FILE.TAB
请参见我在上述代码中遇到的错误是“无效URL…”:您问题中的代码不能抛出任何内容。显示抛出的实际代码(可能是涉及
FtpWebRequest
)另请参见@MartinPrikryl-代码已更新。棘手的是,我之前已经这样做了,我将“host+”:“+remoteFile”更改为“host+”/“+remoteFile”,我仍然会遇到相同的错误,但当我放入“/”时在地址本身的末尾(我更新了上面的代码),它成功了!不知道为什么,但你的回答给了我这个想法,所以谢谢!