相关疑难解决方法(0)

FtpWebRequest下载文件

以下代码旨在通过FTP检索文件.但是,我收到了一个错误.

serverPath = "ftp://x.x.x.x/tmp/myfile.txt";

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath);

request.KeepAlive = true;
request.UsePassive = true;
request.UseBinary = true;

request.Method = WebRequestMethods.Ftp.DownloadFile;                
request.Credentials = new NetworkCredential(username, password);

// Read the file from the server & write to destination                
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) // Error here
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))            
using (StreamWriter destination = new StreamWriter(destinationFile))
{
    destination.Write(reader.ReadToEnd());
    destination.Flush();
}
Run Code Online (Sandbox Code Playgroud)

错误是:

远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限)

该文件肯定存在于远程计算机上,我可以手动执行此ftp(即我有权限).任何人都可以告诉我为什么我可能会收到此错误?

.net c# ftp ftpwebrequest ftpwebresponse

35
推荐指数
3
解决办法
12万
查看次数

PowerShell连接到FTP服务器并获取文件

$ftpServer = "ftp.example.com"
$username ="validUser"
$password ="myPassword"
$localToFTPPath = "C:\ToFTP"
$localFromFTPPath = "C:\FromFTP"
$remotePickupDir = "/Inbox"
$remoteDropDir = "/Outbox"
$SSLMode = [AlexPilotti.FTPS.Client.ESSLSupportMode]::ClearText
$ftp = new-object "AlexPilotti.FTPS.Client.FTPSClient"
$cred = New-Object System.Net.NetworkCredential($username,$password)
$ftp.Connect($ftpServer,$cred,$SSLMode) #Connect
$ftp.SetCurrentDirectory($remotePickupDir)
$ftp.GetFiles($localFromFTPPath, $false) #Get Files
Run Code Online (Sandbox Code Playgroud)

这是我从FTP服务器导入文件的脚本.
但是我不确定是什么remotePickupDir,这个脚本是否正确?

ftp powershell

14
推荐指数
3
解决办法
10万
查看次数

FTP的FileSystemWatcher

如何实现FileSystemWatcherFTP位置(在C#中).这个想法是,无论何时在FTP位置添加任何内容,我都希望将其复制到本地计算机.任何想法都会有所帮助.

这是我之前使用.NET进行选择性FTP下载的问题的后续内容.

.net c# ftp filesystemwatcher

11
推荐指数
3
解决办法
2万
查看次数

使用FtpWebRequest下载文件

我正在尝试使用下载文件FtpWebRequest.

private void DownloadFile(string userName, string password, string ftpSourceFilePath, string localDestinationFilePath)
{
    int bytesRead = 0;
    byte[] buffer = new byte[1024];

    FtpWebRequest request = CreateFtpWebRequest(ftpSourceFilePath, userName, password, true);
    request.Method = WebRequestMethods.Ftp.DownloadFile;

    Stream reader = request.GetResponse().GetResponseStream();
    BinaryWriter writer = new BinaryWriter(File.Open(localDestinationFilePath, FileMode.CreateNew));

    while (true)
    {
        bytesRead = reader.Read(buffer, 0, buffer.Length);

        if (bytesRead == 0)
            break;

        writer.Write(buffer, 0, bytesRead);
    }        
}
Run Code Online (Sandbox Code Playgroud)

它使用CreateFtpWebRequest我创建的这个方法:

private FtpWebRequest CreateFtpWebRequest(string ftpDirectoryPath, string userName, string password, bool keepAlive = false)
{
    FtpWebRequest request = …
Run Code Online (Sandbox Code Playgroud)

.net c# ftp ftpwebrequest c#-4.0

9
推荐指数
2
解决办法
5万
查看次数

PowerShell FTP下载文件和子文件夹

我喜欢编写一个PowerShell脚本来从我的FTP服务器下载所有文件文件.我找到了从一个特定文件夹下载所有文件的脚本,但我也想下载子文件夹及其文件.

#FTP Server Information - SET VARIABLES
$ftp = "ftp://ftp.abc.ch/" 
$user = 'abc' 
$pass = 'abc'
$folder = '/'
$target = "C:\LocalData\Powershell\"

#SET CREDENTIALS
$credentials = new-object System.Net.NetworkCredential($user, $pass)

function Get-FtpDir ($url,$credentials) {
    $request = [Net.WebRequest]::Create($url)
    $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
    if ($credentials) { $request.Credentials = $credentials }
    $response = $request.GetResponse()
    $reader = New-Object IO.StreamReader $response.GetResponseStream() 
    $reader.ReadToEnd()
    $reader.Close()
    $response.Close()
}

#SET FOLDER PATH
$folderPath= $ftp + "/" + $folder + "/"

$Allfiles=Get-FTPDir -url $folderPath -credentials $credentials …
Run Code Online (Sandbox Code Playgroud)

ftp powershell download subdirectory

7
推荐指数
1
解决办法
1万
查看次数

如何从FTP获取文件(使用C#)?

现在我知道如何将文件从一个目录复制到另一个目录,这非常简单.

但现在我需要对来自FTP服务器的文件做同样的事情.你能举例说明如何在更改名称的同时从FTP获取文件吗?

.net c# ftp

5
推荐指数
2
解决办法
2万
查看次数

在C#/ .NET中上传和下载二进制文件到/从FTP服务器下载

我正在使用.NET 4 C#.我正在尝试上传然后将ZIP文件下载到(我的)服务器.

上传我有

using (WebClient client = new WebClient())
{
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(MyUrl);
    request.Method = WebRequestMethods.Ftp.UploadFile;
    request.EnableSsl = false;
    request.Credentials = new NetworkCredential(MyLogin, MyPassword);
    byte[] fileContents = null;
    using (StreamReader sourceStream = new StreamReader(LocalFilePath))
    {
        fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
    }
    request.ContentLength = fileContents.Length;
    using (Stream requestStream = request.GetRequestStream())
    {
        requestStream.Write(fileContents, 0, fileContents.Length);
    }
    FtpWebResponse response = null;
    response = (FtpWebResponse)request.GetResponse();
    response.Close();
}
Run Code Online (Sandbox Code Playgroud)

这似乎有效,因为我在正确大小的服务器上获得了一个文件.

1)如何流式传输,而不是先将其加载到内存中?我将上传非常大的文件.

我下载了

using (WebClient client = new WebClient())
{
    string HtmlResult = String.Empty;
    FtpWebRequest request = …
Run Code Online (Sandbox Code Playgroud)

.net c# ftp webclient ftpwebrequest

5
推荐指数
1
解决办法
9500
查看次数

从FTP上传文件和下载文件

我正在尝试制作一个上传/下载.exe文件的程序FTP

我尝试过使用FtpWebRequest,但我只能成功上传和下载.txt文件.

然后我在这里找到了一个下载解决方案WebClient:

WebClient request = new WebClient();
request.Credentials = new NetworkCredential("username", "password");
byte[] fileData =  request.DownloadData("ftp://myFTP.net/");

FileStream file = File.Create(destinatie);
file.Write(fileData, 0, fileData.Length);

file.Close();
Run Code Online (Sandbox Code Playgroud)

此解决方案有效.但我看到WebClient有一种方法DownloadFile没有奏效.我想是因为它不工作FTPHTTP.我的假设是真的吗?如果不是,我怎么能让它工作?

有没有其他解决方案上传/下载.exe文件到ftp使用FtpWebRequest

c# ftp upload download ftpwebrequest

4
推荐指数
2
解决办法
2万
查看次数

C# - 从FTP下载具有较高修改日期的文件

我有一个带有一些文件的FTP服务器.我在本地目录(in C:\)中有相同的文件.

当我运行该程序时,我希望它搜索FTP服务器中的所有文件,这些文件的最后修改时间戳晚于本地目录中的同一文件(同名),并下载所有已创建的文件.

请问有人能给我一个帮助或提示吗?我会感激所有答案!

c# ftp download last-modified

4
推荐指数
1
解决办法
1805
查看次数

Delete files older than X days from FTP server with PowerShell or batch file

I have to write a script which accesses an FTP server, and then deletes all *.zip files which are older than X days.

As clarification: The script can't run on the FTP server.

This is what I have so far:

$ftpServer = "RandomFTPServer"
$ftpUser = "Username"
$ftpPassword = Read-Host "Password" -AsSecureString

$credentials = New-ObjectSystem.Net.NetworkCredential($ftpUser, $ftpPassword)

function Get-FtpRequest($ftpPath) {
    $ftpRequest = [System.Net.FtpWebRequest]::Create("$ftpServer/$ftpPath")
    $ftpRequest.Credentials = $credentials
    $ftpRequest.UseBinary = $true 
    $ftpRequest.KeepAlive = $true
    $ftpRequest.UsePassive = $true
    return $ftpRequest
}
Run Code Online (Sandbox Code Playgroud)

Any tips on what …

.net ftp powershell batch-file ftpwebrequest

4
推荐指数
1
解决办法
7816
查看次数

删除FTP服务器中的文件夹和子文件夹

我在FTP服务器中创建了文件夹,其中包含登录到服务器的年份,月份和日期,我们可以看到当年点击它显示月份时创建的文件夹,当我点击月份时显示日期.现在我需要删除此文件夹.

下面是我在FTP服务器中删除文件夹的代码

FtpWebResponse responseFileDelete = (FtpWebResponse)ftpRequest.GetResponse();
Run Code Online (Sandbox Code Playgroud)

System.dll中出现未处理的"System.Net.WebException"类型异常
附加信息:远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限).

你能帮我删除一个文件夹吗?

c# ftp ftpwebrequest winforms

3
推荐指数
1
解决办法
1637
查看次数