C# 从Windows Phone 8在FTP服务器上上载文件时引发异常
我想在FTP服务器上上传一个视频文件,我所有的搜索结果都以MSDN managzine文章结尾。它有很棒的示例和库。我尝试了两个FTP URL,一个是Mozilla存储库,另一个是我的机密URL。对我来说,没有什么是有效的,只有例外。我在一个名为的应用程序中尝试了我的FTP URL,它工作正常。下面给出了导出详细信息和输出windows日志 因此,任何人都可以建议我应该在该库中做什么更改?是否有其他可用的工作库或任何其他方式将文件上载到FTPC# 从Windows Phone 8在FTP服务器上上载文件时引发异常,c#,windows-phone-8,ftp,C#,Windows Phone 8,Ftp,我想在FTP服务器上上传一个视频文件,我所有的搜索结果都以MSDN managzine文章结尾。它有很棒的示例和库。我尝试了两个FTP URL,一个是Mozilla存储库,另一个是我的机密URL。对我来说,没有什么是有效的,只有例外。我在一个名为的应用程序中尝试了我的FTP URL,它工作正常。下面给出了导出详细信息和输出windows日志 因此,任何人都可以建议我应该在该库中做什么更改?是否有其他可用的工作库或任何其他方式将文件上载到FTP Exception is thrown in fil
Exception is thrown in file FtpClient.cs, event FtpClientSocket_DataReceived(...), at line "await PrepareDataChannelAsync(Response);" [Line # 253]
ftp.mozilla.org
System.Exception: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (Exception from HRESULT: 0x8007274C)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at WinPhoneFtp.FtpService.FtpClient.<PrepareDataChannelAsync>d__2b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at WinPhoneFtp.FtpService.FtpClient.<FtpClientSocket_DataReceived>d__3.MoveNext()
Output log
FTP Server IP Address: ftp.mozilla.org with port 21
FTP Command Channel Initailized
FTPServer -> 220-
220- ftp.mozilla.org / archive.mozilla.org - files are in /pub/mozilla.org
220-
220- Notice: This server is the only place to obtain nightly builds and needs to
220- remain available to developers and testers. High bandwidth servers that
220- contain the public release files are available at ftp://releases.mozilla.org/
220- If you need to link to a public release, please link to the release server,
220- not here. Thanks!
220-
220- Attempts to download high traffic release files f
FTPServer -> rom this server will get a
220- "550 Permission denied." response.
220
FTPClient -> USER anonymous
FTPServer -> 331 Please specify the password.
FTPClient -> PASS m@m.com
FTPServer -> 230-
230- ftp.mozilla.org / archive.mozilla.org - files are in /pub/mozilla.org
230-
230- Notice: This server is the only place to obtain nightly builds and needs to
230- remain available to developers and testers. High bandwidth servers that
230- contain the public release files are available at ftp://releases.mozilla.org/
230- If you need to link to a public release, please link to the release server,
230- not here. Thanks!
230-
230- Attempts to download high traffic release files f
FTPClient -> PWD
FTPServer -> rom this server will get a
230- "550 Permission denied." response.
230 Login successful.
FTPClient -> PASV
FTPServer -> 257 "/"
FTPServer -> 227 Entered Passive Mode (63,245,215,46,199,76)
FTP Data Channel IPAddress: 63.245.215.46, Port: 50951
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
An exception of type 'System.Exception' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
========================================================================================================================
Confidential FTP URL which required authentication
System.Exception: No connection could be made because the target machine actively refused it. (Exception from HRESULT: 0x8007274D)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at WinPhoneFtp.FtpService.FtpClient.<PrepareDataChannelAsync>d__2b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at WinPhoneFtp.FtpService.FtpClient.<FtpClientSocket_DataReceived>d__3.MoveNext()
Output log
FTP Server IP Address: --CONFIDENTIAL-- with port 21
FTP Command Channel Initailized
FTPServer -> 220 (vsFTPd 2.0.5)
FTPClient -> USER --CONFIDENTIAL--
FTPServer -> 331 Please specify the password.
FTPClient -> PASS --CONFIDENTIAL--
FTPServer -> 230 Login successful.
FTPClient -> PWD
FTPClient -> PASV
FTPServer -> 257 "/"
FTPServer -> 227 Entering Passive Mode (173,193,219,177,156,29)
FTP Data Channel IPAddress: 173.193.219.177, Port: 39938
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
An exception of type 'System.Exception' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
将FtpClient类方法中的PrepareDataChannelAsync(字符串channelInfo)替换为以下方法:
private async Task PrepareDataChannelAsync(String channelInfo)
{
channelInfo = channelInfo.Remove(0, "227 Entering Passive Mode".Length);
int start = channelInfo.IndexOf("(") + 1;
int length = channelInfo.IndexOf(")") - start;
channelInfo = channelInfo.Substring(start, length);
String[] Splits = channelInfo.Split(new char[] { ',', ' ', }, StringSplitOptions.RemoveEmptyEntries);
String Ipaddr = String.Join(".", Splits, 0, 4);
//Configure the IP Address
//Calculate the Data Port
Int32 port = Convert.ToInt32(Splits[4]);
port = (port * 256) + Convert.ToInt32(Splits[5]);
logger.AddLog(String.Format("FTP Data Channel IPAddress: {0}, Port: {1}", Ipaddr, port));
FtpDataChannel = new StreamSocket();
await FtpDataChannel.ConnectAsync(new Windows.Networking.HostName(Ipaddr), port.ToString());
logger.AddLog("FTP Data Channel connected");
}
在
FtpDirectoryBrowser.cs
中的Client\u FtpDirectoryListed
事件中,检查(App.Current作为App.ServerCurrentWorkingDirectory
的值是否不为空后,它工作。我没有在目录列表中获得[One Folder Up]
,因为它是空的。你能帮我吗?另外,请向我解释您更改了什么以使其工作,即您的答案。FTP服务器的响应未正确解析。计算的端口错误,导致连接拒绝。你在上一篇文章中解释的似乎是另一个bug。如果你详细解释一下这个问题,我可以帮你。
private async Task PrepareDataChannelAsync(String channelInfo)
{
channelInfo = channelInfo.Remove(0, "227 Entering Passive Mode".Length);
int start = channelInfo.IndexOf("(") + 1;
int length = channelInfo.IndexOf(")") - start;
channelInfo = channelInfo.Substring(start, length);
String[] Splits = channelInfo.Split(new char[] { ',', ' ', }, StringSplitOptions.RemoveEmptyEntries);
String Ipaddr = String.Join(".", Splits, 0, 4);
//Configure the IP Address
//Calculate the Data Port
Int32 port = Convert.ToInt32(Splits[4]);
port = (port * 256) + Convert.ToInt32(Splits[5]);
logger.AddLog(String.Format("FTP Data Channel IPAddress: {0}, Port: {1}", Ipaddr, port));
FtpDataChannel = new StreamSocket();
await FtpDataChannel.ConnectAsync(new Windows.Networking.HostName(Ipaddr), port.ToString());
logger.AddLog("FTP Data Channel connected");
}