我正在使用上传文件到ftp FtpWebRequest.我需要显示已完成的状态.
到目前为止我的代码是:
public void Upload(string filename, string url)
{
FileInfo fileInf = new FileInfo(filename);
string uri = "ftp://" + url + "/" + fileInf.Name;
FtpWebRequest reqFTP;
//string uri = "ftp://" + Host + "/public_html/testing/blogtest/" + fileInf.Name;
// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(Username, Password);
// By default KeepAlive is true, where the control connection is not closed
// after a command is executed.
reqFTP.KeepAlive …Run Code Online (Sandbox Code Playgroud) 我想将文件从一台服务器上传到另一台FTP服务器,以下是我上传文件的代码,但是它会抛出一个错误:
远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限).
这是我的代码:
string CompleteDPath = "ftp URL";
string UName = "UserName";
string PWD = "Password";
WebRequest reqObj = WebRequest.Create(CompleteDPath + FileName);
reqObj.Method = WebRequestMethods.Ftp.UploadFile;
reqObj.Credentials = new NetworkCredential(UName, PWD);
FileStream streamObj = System.IO.File.OpenRead(Server.MapPath(FileName));
byte[] buffer = new byte[streamObj.Length + 1];
streamObj.Read(buffer, 0, buffer.Length);
streamObj.Close();
streamObj = null;
reqObj.GetRequestStream().Write(buffer, 0, buffer.Length);
reqObj = null;
Run Code Online (Sandbox Code Playgroud)
你能告诉我哪里出错了吗?
我创建了一个小的Windows窗体应用程序,将文件上传到我们客户端的ftp站点之一.但我遇到的问题是,当我在本地计算机上运行此应用程序时,它会成功上传文件.但是,如果我在我们的服务器上运行此程序,我会收到此错误消息;
远程服务器返回错误:(550)文件不可用(例如,找不到文件,无法访问该文件),在此行'objFTPRequest.GetRequestStream();'.
有人知道为什么吗?我需要配置防火墙吗?这是我的代码;
FileInfo objFile = new FileInfo(filename);
FtpWebRequest objFTPRequest;
// Create FtpWebRequest object
objFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/outbox/" + objFile.Name));
// Set Credintials
objFTPRequest.Credentials = new NetworkCredential(ftpUserName, ftpPassword);
// By default KeepAlive is true, where the control connection is
// not closed after a command is executed.
objFTPRequest.KeepAlive = false;
// Set the data transfer type.
objFTPRequest.UseBinary = true;
// Set content length
objFTPRequest.ContentLength = objFile.Length;
// Set request method
objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile;
// Set buffer …Run Code Online (Sandbox Code Playgroud) 我需要一些指导.我需要在C#中开发一个可自定义的FTP,它应该使用App.Config文件进行配置.此外,FTP应该再次从任何客户端将数据推送到任何服务器依赖于配置文件.
如果有人可以指导,如果有任何API或任何其他有用的建议,或者让我朝着正确的方向前进,我将不胜感激.
有没有办法通过网络浏览器上传大文件(超过 80 GB )?以前我一直使用 plupload 上传文件(img、png、jpg),但它似乎不适用于较大的文件。我还想知道如何实现一个用户可以上传的网页,例如 Mega.co.nz 或 Drive.google.com。如果使用网络开发工具无法做到这一点,任何人都可以指导我如何分割和分段上传文件吗?
谢谢。
我试图找出如何将此文件上传到我在C#中的ftp服务器.当它要求getResponse()在ftpwebrequest它抛出一个错误,指出"550 -访问被拒绝".我无法弄清楚为什么.我可以使用相同的凭据与Filezilla连接到服务器.
这是我的代码连接:
private void UploadFileToFTP(HttpPostedFile file, string server, string user, string pass)
{
string uploadUrl = server + file.FileName;
string uploadFileName = Path.GetFileName(file.FileName);
Stream streamObj = file.InputStream;
Byte[] buffer = new Byte[file.ContentLength];
streamObj.Read(buffer, 0, buffer.Length);
streamObj.Close();
streamObj = null;
try
{
SetMethodRequiresCWD();
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(uploadUrl);
//ftp.Method = WebRequestMethods.Ftp.MakeDirectory;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
ftp.UsePassive = true;
ftp.Credentials = new NetworkCredential(user, pass);
FtpWebResponse CreateForderResponse = (FtpWebResponse)ftp.GetResponse();
if (CreateForderResponse.StatusCode == FtpStatusCode.PathnameCreated)
{
string ftpUrl = string.Format("{0}/{1}", uploadUrl, uploadFileName); …Run Code Online (Sandbox Code Playgroud) 我看到这篇文章给出了使用的上传文件到ftp的简单想法WebClient.这很简单,但如何强制它使用SSL?
我需要从 C# 代码将文件夹(包含子文件夹和文件)从一台服务器上传到另一台服务器。我做了一些研究,发现我们可以使用 FTP 来实现这一点。但这样我就只能移动文件,而不能移动整个文件夹。感谢这里的任何帮助。
c# ×8
.net ×6
ftp ×6
file-upload ×2
winforms ×2
asp.net ×1
ftp-client ×1
jquery ×1
php ×1
progress-bar ×1
security ×1