0

我正在尝试从 Windows Phone 8.1 连接到我的 filezilla ftp 服务器。

我现在有这个代码:

StreamSocket s = new StreamSocket();
await s.ConnectAsync(new HostName("192.168.254.53"), "21");
DataWriter writer = new DataWriter(s.OutputStream);
byte[] data = GetBytes(string.Format("{0}\r\n", "USER test"));
writer.WriteBytes(data);
await writer.StoreAsync();
await writer.FlushAsync();
...
static byte[] GetBytes(string str)
{
    byte[] bytes = new byte[str.Length * sizeof(char)];
    System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
    return bytes;
}

ConnectAsync 正常工作:

(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> Connected on port 21, sending welcome message...
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> 220-FileZilla Server version 0.9.49 beta
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> 220-written by Tim Kosse (tim.kosse@filezilla-project.org)
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> 220 Please visit https://filezilla-project.org/

但是对于用户命令,这是服务器收到的:

(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> U
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> 500 Syntax error, command unrecognized.
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> S
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> 500 Syntax error, command unrecognized.
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> E
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> 500 Syntax error, command unrecognized.
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> R
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)> 500 Syntax error, command unrecognized.
(000013)03/03/2015 17:14:13 - (not logged in) (192.168.254.53)>  

我在我的 OutputStream 上正确写入了吗?

4

1 回答 1

0

我现在正在使用这个:

byte[] data = Encoding.Unicode.GetBytes("USER ippon\r");

在调试过程中,我注意到了这一点:

在此处输入图像描述

Encoding.Unicode.GetBytes 函数每隔一个字节添加一个 0 字节。这就是为什么它不起作用!我现在的代码:

StreamSocket s = new StreamSocket();
await s.ConnectAsync(new HostName("192.168.254.53"), "21");
byte[] data = Encoding.Unicode.GetBytes("USER ippon\r");
data = data.Where(val => val != 0).ToArray();
await s.OutputStream.WriteAsync(data.AsBuffer());
await s.OutputStream.FlushAsync();
于 2015-03-04T09:53:44.893 回答