FTP文件上传错误 [英] FTP File Upload Error

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

问题描述

public void FTPFileUpload(string ftpfilepath, string inputfilepath)
    {
        string ftphost = "208.91.199.15";  // your server name or localhost        

        string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
        FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
        ftp.Credentials = new NetworkCredential("tinu", "pass@123");
        //userid and password for the ftp server to given  

        ftp.KeepAlive = true;
        ftp.UseBinary = true;
        ftp.Method = WebRequestMethods.Ftp.UploadFile;
        FileStream fs = File.OpenRead(inputfilepath);
        byte[] buffer = new byte[fs.Length];
        fs.Read(buffer, 0, buffer.Length);
        fs.Close();
        Stream ftpstream = ftp.GetRequestStream();
        ftpstream.Write(buffer, 0, buffer.Length);
        ftpstream.Close();
    }
    private void SaveOnLocal(FileUpload Img)
    {
        string _videopath = Img.FileName;
       
        _videopath = Environment.GetEnvironmentVariable("temp") + "\\" + _videopath;// System.IO.Path.GetFullPath(video.PostedFile.FileName);
        FileIOPermission ioPerm = new FileIOPermission(FileIOPermissionAccess.Write, _videopath);
        ioPerm.Demand();
        Img.SaveAs(_videopath);
       
       FTPFileUpload("/Video/", _videopath);
       
       // System.IO.File.Delete(_videopath);
    }public void FTPFileUpload(string ftpfilepath, string inputfilepath)
    {
        string ftphost = "200.45.459.49";  // your server name or localhost        

        string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
        FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
        ftp.Credentials = new NetworkCredential("Myusername", "MyPasswd");
        //userid and password for the ftp server to given  

        ftp.KeepAlive = true;
        ftp.UseBinary = true;
        ftp.Method = WebRequestMethods.Ftp.UploadFile;
        FileStream fs = File.OpenRead(inputfilepath);
        byte[] buffer = new byte[fs.Length];
        fs.Read(buffer, 0, buffer.Length);
        fs.Close();
        Stream ftpstream = ftp.GetRequestStream();
        ftpstream.Write(buffer, 0, buffer.Length);
        ftpstream.Close();
    }
    private void SaveOnLocal(FileUpload Img)
    {
        string _videopath = Img.FileName;
       
        _videopath = Environment.GetEnvironmentVariable("temp") + "\\" + _videopath;// System.IO.Path.GetFullPath(video.PostedFile.FileName);
        FileIOPermission ioPerm = new FileIOPermission(FileIOPermissionAccess.Write, _videopath);
        ioPerm.Demand();
        Img.SaveAs(_videopath);
       
       FTPFileUpload("/Video/", _videopath);
       
       // System.IO.File.Delete(_videopath);
    }







请求的URI对此FTP命令无效。




The requested URI is invalid for this FTP command.

推荐答案

替换

Replace
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);



by


by

WebRequest ftp = WebRequest.Create(ftpfullpath + FileName);


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

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