使用 VB.NET 将文件上传到 FTP 站点

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

问题描述

我从这个 link 获得了这个工作代码,用于将文件上传到一个 ftp 站点:

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	est.txt")

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

不知道,如果ftp目录下已经存在该文件,会不会覆盖该文件?

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

推荐答案

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

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 站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
How to store delegates in a List(如何将代表存储在列表中)
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
CreateDelegate with unknown types(具有未知类型的 CreateDelegate)
Does Funclt;Tgt;.BeginInvoke use the ThreadPool?(Funclt;Tgt;.BeginInvoke 使用线程池吗?)
How to create a delegate to an instance method with a null target?(如何为具有空目标的实例方法创建委托?)