0

I use this code to upload file to server.

Dim clsRequest As System.Net.FtpWebRequest = _
                DirectCast(System.Net.WebRequest.Create(a), System.Net.FtpWebRequest)
            clsRequest.Credentials = New System.Net.NetworkCredential(username, pwd)
            clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

            ' read in file...
            Dim bFile() As Byte = System.IO.File.ReadAllBytes(pdfPath)

            ' upload file...
            Dim clsStream As System.IO.Stream = _
                clsRequest.GetRequestStream()
            clsStream.Write(bFile, 0, bFile.Length)
            clsStream.Close()
            clsStream.Dispose()

But is show error unable to connect to remote server at line Dim clsStream As System.IO.Stream = _ clsRequest.GetRequestStream(). Any wrong?

4

1 回答 1

0

使用 FTP 协议需要在远程机器上运行专用的 FTP 服务器软件。没有它,FTP 无法访问网络驱动器。如果您只想访问网络上的文件,请从这个 SO 问题开始: Copying files to a mapped drive while user is not logged in (scheduled task)

出于安全原因,我强烈建议在此之前执行几个步骤: a) 不要像 C$ 一样打开 root 共享。b) 在您的“远程”服务器上创建特定共享,在该服务器上,您仅为该特定目的授予用户访问权限。

进一步阅读 FTP:http ://en.wikipedia.org/wiki/File_Transfer_Protocol

于 2013-07-26T08:56:55.927 回答