使用FTP和文件上传控件上传文件 [英] Upload file using FTP and fileupload control

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

问题描述

我想从fileupload控件上载一个文件,但是安装了http,我想使用ftp ...有人可以帮助我吗?在此先感谢...

i want to upload a file from fileupload control but insted of using http i want to use ftp... can any one help me out? thanks in advance...

推荐答案



我也遇到过同样的情况,R& D的一些工作将我引向以下解决方案.
在一个简单的表单上,有一个FileUpload控件(例如FileUpload1)和一个Button控件(例如Button1).在按钮的Click事件上,编写以下代码

Hi,

Me too came across same situation, and bit of R&D leads me to the following solution.
On a simple form there is a FileUpload control (say FileUpload1) and a Button Control (say Button1). On Click event of button write following code

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim f as bool = Upload(FileUpload1.FileBytes, FileUpload1.FileName, "abcftp", "abc@ftp", "ftp://ftp.someftp.com")
    Response.Write(f = True, "Uploaded Successfully", "Unable to Upload")
End Sub



Upload()函数可以发挥所有魔力



Upload() function does all the magic

 Public Function Upload(FileByte() As Byte, FileName As String, ftpUserID As String, ftpPassword As String, ftpURL As String) As Boolean
    Dim retValue As Boolean = False
    Try
        Dim ftpFullPath As String = ftpURL + "/" + FileName
        Dim ftp As FtpWebRequest = FtpWebRequest.Create(New Uri(ftpFullPath))
        ftp.Credentials = New NetworkCredential(ftpUserID, ftpPassword)
        ftp.KeepAlive = True
        ftp.UseBinary = True
        ftp.Method = WebRequestMethods.Ftp.UploadFile
        Dim ftpStream As Stream = ftp.GetRequestStream()
        ftpStream.Write(FileByte, 0, FileByte.Length)
        ftpStream.Close()
        ftpStream.Dispose()
        retValue = True
    Catch ex As Exception
        Throw ex
    End Try
    Return retValue
End Function



我希望这会有所帮助.
谢谢.



I hope this will help.
Thanks.


检查一下:
C#中的简单FTP库 [使用FTP将文件上传到服务器 [
Check this out:
Simple FTP library in C#[^]
Upload file to server using FTP[^]


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

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