使用VB.NET将文件上传到FTP站点 [英] Upload file to FTP site using VB.NET

查看:362
本文介绍了使用VB.NET将文件上传到FTP站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从此链接获取此工作代码,以上传文件到一个FTP站点:$ b​​
$ b

 '设置请求... 
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create(ftp://ftp.myserver.com/test.txt),System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net。 NetworkCredential(myusername,mypassword)
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

'读入文件...
Dim bFile() As Byte = System.IO.File.ReadAllBytes(C:\Temp\test.txt)

'上传文件...
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
clsStream.Write(bFile,0,bFile.Length)
clsStream.Close()
clsStream.Dispose()

我想知道,如果该文件已存在于ftp目录中,该文件将被覆盖?

解决方案

查看 MSDN 文档,它映射到FTP STOR命令。查看FTP STOR命令的定义,如果用户有权限,它将覆盖现有文件。



所以在这种情况下,是的,文件会被覆盖。 p>

I have this working code from this link, to upload a file to an ftp site:

' set up request...
Dim clsRequest As System.Net.FtpWebRequest = _
    DirectCast(System.Net.WebRequest.Create("ftp://ftp.myserver.com/test.txt"), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential("myusername", "mypassword")
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

' read in file...
Dim bFile() As Byte = System.IO.File.ReadAllBytes("C:\Temp\test.txt")

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

I wonder, if the file already exists in the ftp directory, the file will be overwritten?

解决方案

Looking at the MSDN documentation this maps to the FTP STOR command. Looking at the definition for the FTP STOR command it will overwrite existing files, if the user has permissions.

So in this case, yes the file would be overwritten.

这篇关于使用VB.NET将文件上传到FTP站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆