2

我们有一个 OpenVMS (VMS) Alpha 服务器,我需要访问它才能通过 FTP 传输文件。问题是它不支持FtpWebRequest启动连接时使用的命令(ftp://192.168.xx.xx),除了 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 命令进行连接: 在此处输入图像描述

有什么建议么??

4

1 回答 1

3

URL 没有表单

ftp://192.168.xx.xx:FILE.TAB

ftp://192.168.xx.xx/FILE.TAB

https://en.wikipedia.org/wiki/URL

于 2015-03-03T09:20:09.293 回答