gpt4 book ai didi

c# - 为什么 FtpWebRequest 将用户登录添加为目标数据集的一部分?

转载 作者:行者123 更新时间:2023-12-02 12:43:27 28 4
gpt4 key购买 nike

我最近使用 C# 将 Windows cmd 转换为 FtpWebRequest,以将文件上传到 IBM 大型机数据集。 Look here

运行两者时,我发现它们上传到不同的数据集,而它们应该完全相同,FtpWebRequest 正在将用户登录信息添加到数据集。

cmd 上的代码将文件上传到:'ABCD.AA.C58FC.ABC1FD.ZP3ABC' 数据集,C# 代码将文件上传到:USERME.ABCD.AA.C58FC .ABC1FD.ZP3ABC。我需要 C# 代码上传到数据集:ABCD.AA.C58FC.ABC1FD.ZP3ABC。我知道他们正在上传到不同的数据集,因为在使用 C# 上传文件后,如果我使用 cmd 来获取文件,例如:

get 'ABCD.AA.C58FC.ABC1FD.ZP3ABC' examplefile`

没有给我任何东西,但如果我这样做:

get 'USERME.ABCD.AA.C58FC.ABC1FD.ZP3ABC' examplefile`

我拿到了文件。我在这里缺少什么?

这是 Windows cmd:

Open abc.wyx.state.aa.bb
User
Pass
lcd c:\Transfer>
Put examplefile 'ABCD.AA.C58FC.ABC1FD.ZP3ABC'
close
bye

此处 C# 使用 FtpWebRequest

string ftpfullpath = @"ftp://abc.wyx.state.aa.bb/'ABCD.AA.C58FC.ABC1FD.ZP3ABC'";            
try
{

FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential(user, password);

ftp.KeepAlive = true;
ftp.UseBinary = false; //Use ascii.

ftp.Method = WebRequestMethods.Ftp.UploadFile;

FileStream fs = File.OpenRead(source);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();

Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}

这是来自 C# 的网络日志:

System.Net Information: 0 : [8736] FtpWebRequest#53578024::.ctor(ftp://abc.wyx.state.aa.bb/ABCD.AA.C58FC.ABC1FD.ZP3ABC)
System.Net Information: 0 : [8736] FtpWebRequest#53578024::GetRequestStream(Method=STOR.)
System.Net Information: 0 : [8736] Current OS installation type is 'Client'.
System.Net Information: 0 : [8736] RAS supported: True
System.Net Error: 0 : [8736] Can't retrieve proxy settings for Uri 'ftp://abc.wyx.state.aa.bb/ABCD.AA.C58FC.ABC1FD.ZP3ABC'. Error code: 12180.
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Created connection from 10.11.12.134:56789 to 123.456.78.90:12.
System.Net Information: 0 : [8736] Associating FtpWebRequest#53578024 with FtpControlStream#38366678
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Received response [220-FTP 17:02:28 on 2015-05-26.
220- Warning!
220 Connection will close if idle for more than 5 minutes.]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Sending command [USER USERME]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Received response [331 Send password please.]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Sending command [PASS ********]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Received response [230 USERME is logged on. Working directory is "USERME.".]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Received response [501 command OPTS aborted -- no options supported for utf8]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Sending command [PWD]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Received response [257 "'USERME.'" is working directory.]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Sending command [TYPE A]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Received response [200 Representation type is Ascii NonPrint]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Sending command [PASV]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Received response [227 Entering Passive Mode (204,122,60,60,157,239)]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Sending command [STOR ABCD.AA.C58FC.ABC1FD.ZP3ABC]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Received response [125 Storing data set USERME.ABCD.AA.C58FC.ABC1FD.ZP3ABC]
System.Net Information: 0 : [8736] FtpControlStream#38366678 - Received response [250 Transfer completed successfully.]
System.Net Information: 0 : [8736] FtpWebRequest#53578024::(Releasing FTP connection#38366678.)

最佳答案

用单引号将 C# 中的文件名括起来。

我知道为什么会发生这种情况(因为 TSO/ISPF 会用用户 ID 预先创建一个创建的文件名),但我不知道为什么在你的情况下会发生这种情况(除非 C# 的东西认为这是必要的)但这就是解决问题的方法。

好的,我看到您(可能)已经这样做了,这似乎意味着 C# 正在剥离它们。因此,您需要“保护”您给出的明显单引号。

一些主要镜头:

"'abcd.efg.hij'"
"''abcd.efg.hij''"
''abcd.efg.hij''

你明白了。

有 C# 内容的文档吗?

关于c# - 为什么 FtpWebRequest 将用户登录添加为目标数据集的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30472045/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com