使用 FtpWebRequest 上传文件时获取 "Invalid URL"

Getting "Invalid URL" when uploading file using FtpWebRequest

我们有一个 OpenVMS (VMS) Alpha 服务器,我需要访问它才能通过 FTP 传输文件。问题是它不支持启动连接时FtpWebRequest中使用的命令(ftp://192.168.xx.xx),除了FtpWebRequest之外,我还可以使用其他FTP功能吗?

我之前一直在 Windows 和 Unix 环境中使用我的代码,但这是我第一次在 VMS OS 上使用我的代码,我也可以通过 [=33] 访问服务器=] 使用命令提示符。

下面是我的代码:

//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;
    }

我在上面的代码中得到的错误是"Invalid URL...."。

当我尝试在浏览器上 运行 时出现错误:

但我可以在 windows 中使用常用的 cmd 命令进行连接:

有什么建议吗??

URL没有表格

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

但是

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

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