在c#中上传FTP文件时出错 [英] error on FTP file uploading in c#

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

问题描述

错误 - 配置系统无法初始化



我在FtpWebRequest.Create(uri)上出错了



FileInfo fileInf = new FileInfo(FileName);

string uri =ftp://+ ftpServerIP +//; // + fileInf.Name;

FtpWebRequest reqFTP;



//从提供的Uri创建FtpWebRequest对象

reqFTP =(FtpWebRequest) FtpWebRequest.Create(uri) );



//提供WebPermission Credintials

reqFTP.Credentials = new NetworkCredential(ftpUserID,ftpPassword);



//默认情况下,KeepAlive为true,控制连接为

//执行命令后未关闭。

reqFTP.KeepAlive = false;



//指定要执行的命令。

reqFTP.Method = WebRequestMethods.Ftp。 UploadFile;



// Uploding work .....





如何解决这个问题

Error- Configuration system failed to initialize

I got error on FtpWebRequest.Create(uri)

FileInfo fileInf = new FileInfo(FileName);
string uri = "ftp://" + ftpServerIP + "//";// +fileInf.Name;
FtpWebRequest reqFTP;

// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);

// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);

// By default KeepAlive is true, where the control connection is
// not closed after a command is executed.
reqFTP.KeepAlive = false;

// Specify the command to be executed.
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

// Uploding work .....


How to resolve this problem

推荐答案

可能是您的文件名已存在于FTP服务器中请正确检查。



否则请检查以下代码。它将覆盖FTP服务器中的现有文件。







string _FtpFilePath =ftp://198.XX.XX.YYYY//test1 ;

string _LocalFilePath =D:\\Dummy\\1234.xml;



WebClient FTP_Upload = new WebClient();

FTP_Upload.C​​redentials = new System.Net.NetworkCredential(_UserName,_Password);

FTP_Upload.UploadFile(_FtpFilePath +/+ Path.GetFileName( _LocalFilePath),_ LocalFilePath);

FTP_Upload.Dispose();
May be your file name already exists in FTP server please check properly.

Otherwise check below code.It will overwrite the existing File in FTP server.



string _FtpFilePath="ftp://198.XX.XX.YYYY//test1";
string _LocalFilePath="D:\\Dummy\\1234.xml";

WebClient FTP_Upload = new WebClient();
FTP_Upload.Credentials = new System.Net.NetworkCredential(_UserName, _Password);
FTP_Upload.UploadFile(_FtpFilePath + "/"+Path.GetFileName(_LocalFilePath),_LocalFilePath);
FTP_Upload.Dispose();


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

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