0

Try to upload a file to an IBM Mainframe using FtpWebRequest give the 227 Entering Passive Mode error, using WinSCP console works just fine. I have visited all possible posts here on StackOverflow even this one that I asked my self a few years ago Use C# to FTP file to mainframe including dataset - Translate FTP script to FtpWebRequest code

Following are the C# code, the WinSCP script, and both logs.

C# Code:

        string user = "AXXXXXX";
        string pwd = "******";
        var serverUri = @"ftp://yyy.yy.yy.yy.yy/'AAAA.BBB.CCCC.DDDDD'";

        // Get the object used to communicate with the server.
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
        request.Credentials = new NetworkCredential(user, pwd);
        request.EnableSsl = true;
        request.UseBinary = false;
        request.Method = WebRequestMethods.Ftp.UploadFile;


        FileStream fs = File.OpenRead(@"D:\TEST.TXT");
        byte[] buffer = new byte[fs.Length];
        fs.Read(buffer, 0, buffer.Length);
        fs.Close();

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

Winscp Script:

option batch on
option confirm off
open ftp://AXXXXXX:******@yyy.yy.yy.yy.yy:21 -explicittls
ASCII
cd /
cd 'AAAA.BBB.CCCC.DDDDD'
put D:\TEST4.TXT TEST4.TXT
bye

Here C# log

System.Net Information: 0 : [75372] FtpWebRequest#45004109::.ctor(ftp://yyy.yy.yy.yy.yy/'AAAA.BBB.CCCC.DDDDD')
System.Net Information: 0 : [75372] Current OS installation type is 'Client'.
System.Net Information: 0 : [75372] FtpWebRequest#45004109::GetRequestStream(Method=STOR.)
System.Net Information: 0 : [75372] RAS supported: True
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Created connection from 192.168.1.10:59723 to 207.192.50.50:21.
System.Net Information: 0 : [75372] Associating FtpWebRequest#45004109 with FtpControlStream#21454193
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Received response [220-FTP 10:24:35 on 2022-09-21.
220-                          Warning!
220- This is a government Computer System and is the property of the
220-State of . Users have no expectation of privacy. Use
220- of this computer system is subject to monitoring or other review
220-  by the government operator or others. Unauthorized or improper
220-use of this system may result in administrative disciplinary action
220-               and civil and criminal penalties.
220-
220-      Use of this system constitutes consent to monitoring.
220 Connection will close if idle for more than 5 minutes.]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Sending command [AUTH TLS]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Received response [234 Security environment established - ready for negotiation]
System.Net Information: 0 : [75372] TlsStream#58870012::.ctor(host=yyy.yy.yy.yy.yy, #certs=0, checkCertificateRevocationList=False, sslProtocols=None)
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Sending command [USER AXXXXXX]
System.Net Information: 0 : [75372] SecureChannel#60068066::.ctor(hostname=yyy.yy.yy.yy.yy, #clientCertificates=0, encryptionPolicy=RequireEncryption)
System.Net Information: 0 : [75372] Enumerating security packages:
System.Net Information: 0 : [75372]     Negotiate
System.Net Information: 0 : [75372]     NegoExtender
System.Net Information: 0 : [75372]     Kerberos
System.Net Information: 0 : [75372]     NTLM
System.Net Information: 0 : [75372]     TSSSP
System.Net Information: 0 : [75372]     pku2u
System.Net Information: 0 : [75372]     WDigest
System.Net Information: 0 : [75372]     Schannel
System.Net Information: 0 : [75372]     Microsoft Unified Security Protocol Provider
System.Net Information: 0 : [75372]     MSOIDSSP
System.Net Information: 0 : [75372]     Default TLS SSP
System.Net Information: 0 : [75372]     CREDSSP
System.Net Information: 0 : [75372] SecureChannel#60068066 - Left with 0 client certificates to choose from.
System.Net Information: 0 : [75372] SecureChannel#60068066::.AcquireClientCredentials, new SecureCredential() (flags=(ValidateManual, NoDefaultCred, SendAuxRecord, UseStrongCrypto), m_ProtocolFlags=(Zero), m_EncryptionPolicy=RequireEncryption)
System.Net Information: 0 : [75372] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent  = Outbound, scc     = System.Net.SecureCredential2)
System.Net Information: 0 : [75372] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = (null), targetName = yyy.yy.yy.yy.yy, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [75372] InitializeSecurityContext(In-Buffer length=0, Out-Buffer length=181, returned code=ContinueNeeded).
System.Net Information: 0 : [75372] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 849b40:858d40, targetName = yyy.yy.yy.yy.yy, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [75372] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=190, returned code=ContinueNeeded).
System.Net Information: 0 : [75372] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 849b40:858d40, targetName = yyy.yy.yy.yy.yy, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [75372] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=ContinueNeeded).
System.Net Information: 0 : [75372] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 849b40:858d40, targetName = yyy.yy.yy.yy.yy, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [75372] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=OK).
System.Net Information: 0 : [75372] Remote certificate: [Version]
  V3

[Subject]
  CN=yyy.yy.yy.yy.yy, O=Executive Office of the State of , L=, S=, C=US
  Simple Name: yyy.yy.yy.yy.yy
  DNS Name: yyy.yy.yy.yy.yy

[Issuer]
  CN=DigiCert Global G2 TLS RSA SHA256 2020 CA1, O=DigiCert Inc, C=US
  Simple Name: DigiCert Global G2 TLS RSA SHA256 2020 CA1
  DNS Name: DigiCert Global G2 TLS RSA SHA256 2020 CA1

[Serial Number]
  02A8DB5DE0952CAF2964D096035F8418

[Not Before]
  5/24/2022 8:00:00 PM

[Not After]
  6/25/2023 7:59:59 PM

[Thumbprint]
  4FE2A581DC2258EF5FB98C1E19BA41DBB070FF57

[Signature Algorithm]
  sha256RSA(1.2.840.113549.1.1.11)

[Public Key]
  Algorithm: RSA
  Length: 2048
  Key Blob: 30 82 01 0a 02 82 01 01 00 d3 f1 39 be d1 d5 28 1a fc c9 86 82 24 28 90 3c 53 a4 d4 75 7d a5 3c 76 4d 66 b3 ac b1 58 fd 55 b2 ca 4f 24 24 5c 39 81 1f ec 23 36 dc 85 13 53 b5 3a 63 84 2b a8 3b f1 84 88 47 0e 34 eb 7a a7 28 3d 67 20 4f bb bb 5c 42 87 b0 e0 e3 71 0a 26 96 2f f0 74 85 57 92 f1 2....
System.Net Information: 0 : [75372] SecureChannel#60068066 - Remote certificate has errors:
System.Net Information: 0 : [75372] SecureChannel#60068066 -    Certificate name mismatch.
System.Net Information: 0 : [75372] SecureChannel#60068066 - Remote certificate was verified as valid by the user.
System.Net Information: 0 : [75372] ProcessAuthentication(Protocol=Tls12, Cipher=Aes256 256 bit strength, Hash=Sha384 0 bit strength, Key Exchange=DiffieHellman 1024 bit strength).
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Received response [331 Send password please.]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Sending command [PASS ********]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Received response [230 AXXXXXX is logged on.  Working directory is "AXXXXXX.".]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Sending command [PBSZ 0]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Received response [200 Protection buffer size accepted]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Sending command [PROT P]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Received response [200 Data connection protection set to private]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Received response [501 command OPTS aborted -- no options supported for utf8]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Sending command [PWD]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Received response [257 "'AXXXXXX.'" is working directory.]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Sending command [TYPE A]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Received response [200 Representation type is Ascii NonPrint]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Sending command [PASV]
System.Net Information: 0 : [75372] FtpControlStream#21454193 - Received response [227 Entering Passive Mode (207,192,33,30,195,108)]
System.Net Information: 0 : [75372] FtpWebRequest#45004109::(Releasing FTP connection#21454193.)
System.Net Error: 0 : [75372] Exception in FtpWebRequest#45004109::GetRequestStream - The remote server returned an error: 227 Entering Passive Mode (207,192,33,30,195,108)
..
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.FtpWebRequest.RequestCallback(Object obj)
   at System.Net.CommandStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at System.IO.Stream.Dispose()
   at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
   at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
   at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
   at System.Net.FtpWebRequest.GetRequestStream()
System.Net Error: 0 : [75372] Exception in AppDomain#33675143::UnhandledExceptionHandler - The remote server returned an error: 227 Entering Passive Mode (207,192,33,30,195,108)

WinSCP Log:

. 2022-09-20 16:27:13.865 --------------------------------------------------------------------------
. 2022-09-20 16:27:13.865 WinSCP Version 5.15.3 (Build 9730) (OS 10.0.19043 - Windows 10 Enterprise)
. 2022-09-20 16:27:13.865 Configuration: nul
. 2022-09-20 16:27:13.865 Log level: Normal
. 2022-09-20 16:27:13.865 Local account: XXXXX\xxxxx
. 2022-09-20 16:27:13.866 Working directory: D:\WinSCP
. 2022-09-20 16:27:13.866 Process ID: 20996
. 2022-09-20 16:27:13.866 Command-line: "D:\WinSCP\WinSCP.exe" /console=5.15.3 /consoleinstance=_59692_538 "/console" "/log=logfile.log" "/script=FTPSput.txt" "/ini=nul" 
. 2022-09-20 16:27:13.866 Time zone: Current: GMT-4, Standard: GMT-5 (Eastern Standard Time), DST: GMT-4 (Eastern Daylight Time), DST Start: 3/13/2022, DST End: 11/6/2022
. 2022-09-20 16:27:13.871 Login time: Tuesday, September 20, 2022 4:27:13 PM
. 2022-09-20 16:27:13.871 --------------------------------------------------------------------------
. 2022-09-20 16:27:13.871 Script: Retrospectively logging previous script records:
> 2022-09-20 16:27:13.871 Script: option batch on
< 2022-09-20 16:27:13.871 Script: batch           on        
> 2022-09-20 16:27:13.871 Script: option confirm off
< 2022-09-20 16:27:13.871 Script: confirm         off       
> 2022-09-20 16:27:13.871 Script: open ftp://AXXXXXX:***@yyy.yy.yy.yy.yy:21 -explicittls
. 2022-09-20 16:27:13.871 --------------------------------------------------------------------------
. 2022-09-20 16:27:13.871 Session name: AXXXXXX@yyy.yy.yy.yy.yy (Ad-Hoc site)
. 2022-09-20 16:27:13.871 Host name: yyy.yy.yy.yy.yy (Port: 21)
. 2022-09-20 16:27:13.871 User name: AXXXXXX (Password: Yes, Key file: No, Passphrase: No)
. 2022-09-20 16:27:13.871 Transfer Protocol: FTP
. 2022-09-20 16:27:13.871 Ping type: Dummy, Ping interval: 30 sec; Timeout: 15 sec
. 2022-09-20 16:27:13.871 Disable Nagle: No
. 2022-09-20 16:27:13.871 Proxy: None
. 2022-09-20 16:27:13.871 Send buffer: 262144
. 2022-09-20 16:27:13.871 UTF: Auto
. 2022-09-20 16:27:13.871 FTPS: Explicit TLS/SSL [Client certificate: No]
. 2022-09-20 16:27:13.871 FTP: Passive: Yes [Force IP: Auto]; MLSD: Auto [List all: Auto]; HOST: Auto
. 2022-09-20 16:27:13.871 Session reuse: Yes
. 2022-09-20 16:27:13.871 TLS/SSL versions: TLSv1.0-TLSv1.2
. 2022-09-20 16:27:13.871 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2022-09-20 16:27:13.871 Cache directory changes: Yes, Permanent: Yes
. 2022-09-20 16:27:13.871 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2022-09-20 16:27:13.871 Timezone offset: 0h 0m
. 2022-09-20 16:27:13.871 --------------------------------------------------------------------------
. 2022-09-20 16:27:13.874 Connecting to yyy.yy.yy.yy.yy ...
. 2022-09-20 16:27:13.910 Connected with yyy.yy.yy.yy.yy, negotiating TLS connection...
< 2022-09-20 16:27:13.960 220-FTP 16:27:14 on 2022-09-20.
< 2022-09-20 16:27:13.960 220-                          Warning!
< 2022-09-20 16:27:13.961 220- This is a government Computer System and is the property of the
< 2022-09-20 16:27:13.961 220-State of . Users have no expectation of privacy. Use
< 2022-09-20 16:27:13.961 220- of this computer system is subject to monitoring or other review
< 2022-09-20 16:27:13.961 220-  by the government operator or others. Unauthorized or improper
< 2022-09-20 16:27:13.961 220-use of this system may result in administrative disciplinary action
< 2022-09-20 16:27:13.961 220-               and civil and criminal penalties.
< 2022-09-20 16:27:13.961 220-
< 2022-09-20 16:27:13.961 220-      Use of this system constitutes consent to monitoring.
< 2022-09-20 16:27:13.961 220 Connection will close if idle for more than 5 minutes.
> 2022-09-20 16:27:13.961 AUTH TLS
< 2022-09-20 16:27:14.058 234 Security environment established - ready for negotiation
. 2022-09-20 16:27:14.271 Verifying certificate for "Executive Office of the State of " with fingerprint 4f:e2:a5:81:dc:22:58:ef:5f:b9:8c:1e:19:ba:41:db:b0:70:ff:57 and 19 failures
. 2022-09-20 16:27:14.271 Asking user:
. 2022-09-20 16:27:14.271 **The server's certificate is not known. You have no guarantee that the server is the computer you think it is.**
. 2022-09-20 16:27:14.271 
. 2022-09-20 16:27:14.271 Server's certificate details follow:
. 2022-09-20 16:27:14.271 
. 2022-09-20 16:27:14.271 Issuer:
. 2022-09-20 16:27:14.271 - Organization: DigiCert Inc, DigiCert Global G2 TLS RSA SHA256 2020 CA1
. 2022-09-20 16:27:14.271 - Location: US
. 2022-09-20 16:27:14.271 
. 2022-09-20 16:27:14.271 Subject:
. 2022-09-20 16:27:14.271 - Organization: Executive Office of the State of , sccb.its.state.nc.us
. 2022-09-20 16:27:14.271 - Location: US, , 
. 2022-09-20 16:27:14.271 
. 2022-09-20 16:27:14.271 Valid: 5/25/2022 12:00:00 AM - 6/25/2023 11:59:59 PM
. 2022-09-20 16:27:14.271 
. 2022-09-20 16:27:14.271 Fingerprint (SHA-1): 4f:e2:a5:81:dc:22:58:ef:5f:b9:8c:1e:19:ba:41:db:b0:70:ff:57
. 2022-09-20 16:27:14.271 
. 2022-09-20 16:27:14.271 Summary: Self-signed certificate in certificate chain. The error occurred at a depth of 3 in the certificate chain.
. 2022-09-20 16:27:14.271 
. 2022-09-20 16:27:14.271 Certificate was not issued for this server. You might be connecting to a server that is pretending to be "yyy.yy.yy.yy.yy".
. 2022-09-20 16:27:14.271 
. 2022-09-20 16:27:14.271 If you trust this certificate, press Yes. To connect without storing certificate, press No. To abandon the connection press Cancel.
. 2022-09-20 16:27:14.271 
. 2022-09-20 16:27:14.271 Continue connecting and store the certificate? ()
. 2022-09-20 16:27:17.451 Using TLSv1.2, cipher TLSv1/SSLv3: DHE-RSA-AES256-GCM-SHA384, 2048 bit RSA, DHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=DH       Au=RSA  Enc=AESGCM(256) Mac=AEAD
. 2022-09-20 16:27:17.452 TLS connection established. Waiting for welcome message...
> 2022-09-20 16:27:17.452 USER AXXXXXX
< 2022-09-20 16:27:17.479 331 Send password please.
> 2022-09-20 16:27:17.479 PASS ********
< 2022-09-20 16:27:17.547 230 AXXXXXX is logged on.  Working directory is "AXXXXXX.".
> 2022-09-20 16:27:17.547 SYST
. 2022-09-20 16:27:17.571 Server is known not to support LIST -a
< 2022-09-20 16:27:17.571 215 MVS is the operating system of this server. FTP Server is running on z/OS.
> 2022-09-20 16:27:17.571 FEAT
< 2022-09-20 16:27:17.594 211- Extensions supported
< 2022-09-20 16:27:17.594  UTF8
< 2022-09-20 16:27:17.595  LANG en*
< 2022-09-20 16:27:17.595  AUTH TLS
< 2022-09-20 16:27:17.595  PBSZ
< 2022-09-20 16:27:17.595  PROT
< 2022-09-20 16:27:17.595 211 End
> 2022-09-20 16:27:17.595 OPTS UTF8 ON
< 2022-09-20 16:27:17.619 501 command OPTS aborted -- no options supported for UTF8
> 2022-09-20 16:27:17.619 PBSZ 0
< 2022-09-20 16:27:17.644 200 Protection buffer size accepted
> 2022-09-20 16:27:17.644 PROT P
< 2022-09-20 16:27:17.667 200 Data connection protection set to private
. 2022-09-20 16:27:17.667 Connected
. 2022-09-20 16:27:17.668 --------------------------------------------------------------------------
. 2022-09-20 16:27:17.668 Using FTP protocol.
. 2022-09-20 16:27:17.668 Doing startup conversation with host.
> 2022-09-20 16:27:17.669 PWD
< 2022-09-20 16:27:17.694 257 "'AXXXXXX.'" is working directory.
. 2022-09-20 16:27:17.694 Getting current directory name.
. 2022-09-20 16:27:17.694 Startup conversation with host finished.
< 2022-09-20 16:27:17.695 Script: Active session: [1] AXXXXXX@yyy.yy.yy.yy.yy
> 2022-09-20 16:27:17.696 Script: ASCII
< 2022-09-20 16:27:17.696 Script: transfer        ascii     
> 2022-09-20 16:27:17.697 Script: cd /
. 2022-09-20 16:27:17.697 Changing directory to "/".
> 2022-09-20 16:27:17.697 CWD /
< 2022-09-20 16:27:17.722 250 HFS directory / is the current working directory
. 2022-09-20 16:27:17.722 Getting current directory name.
> 2022-09-20 16:27:17.722 PWD
< 2022-09-20 16:27:17.744 257 "/" is the HFS working directory.
< 2022-09-20 16:27:17.744 Script: /
> 2022-09-20 16:27:17.745 Script: cd 'AAAA.BBB.CCCC.DDDDD'
. 2022-09-20 16:27:17.745 Changing directory to "'AAAA.BBB.CCCC.DDDDD'".
> 2022-09-20 16:27:17.745 CWD 'AAAA.BBB.CCCC.DDDDD'
< 2022-09-20 16:27:17.776 250 "AAAA.BBB.CCCC.DDDDD." is the working directory name prefix.
. 2022-09-20 16:27:17.776 Getting current directory name.
> 2022-09-20 16:27:17.776 PWD
< 2022-09-20 16:27:17.801 257 "'AAAA.BBB.CCCC.DDDDD.'" is working directory.
< 2022-09-20 16:27:17.801 Script: /'AAAA.BBB.CCCC.DDDDD.'
> 2022-09-20 16:27:17.802 Script: put D:\TEST4.TXT TEST4.TXT
. 2022-09-20 16:27:17.802 Copying 1 files/directories to remote directory "/'AAAA.BBB.CCCC.DDDDD.'" - total size: 51
. 2022-09-20 16:27:17.802   PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask: TEST4.TXT
. 2022-09-20 16:27:17.802   TM: A; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; EncryptNewFiles: Yes; ExcludeHiddenFiles: No; ExcludeEmptyDirectories: No; InclM: ; ResumeL: 0
. 2022-09-20 16:27:17.802   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2022-09-20 16:27:17.802 File: 'D:\TEST4.TXT' [2022-09-20T04:00:00.000Z] [51]
. 2022-09-20 16:27:17.803 Copying "D:\TEST4.TXT" to remote directory started.
. 2022-09-20 16:27:17.803 Ascii transfer mode selected.
. 2022-09-20 16:27:17.803 Starting upload of D:\TEST4.TXT
> 2022-09-20 16:27:17.803 TYPE A
< 2022-09-20 16:27:17.826 200 Representation type is Ascii NonPrint
> 2022-09-20 16:27:17.826 PASV
< 2022-09-20 16:27:17.849 227 Entering Passive Mode (207,192,33,30,195,118)
> 2022-09-20 16:27:17.849 STOR TEST4.TXT
. 2022-09-20 16:27:17.849 Connecting to 207.192.33.30:50038 ...
< 2022-09-20 16:27:17.936 125 Storing data set AAAA.BBB.CCCC.DDDDD.TEST4.TXT
. 2022-09-20 16:27:17.959 Session ID reused
. 2022-09-20 16:27:17.960 Using TLSv1.2, cipher TLSv1/SSLv3: DHE-RSA-AES256-GCM-SHA384, 2048 bit RSA, DHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=DH       Au=RSA  Enc=AESGCM(256) Mac=AEAD
. 2022-09-20 16:27:17.961 TLS connection established
< 2022-09-20 16:27:18.005 250 Transfer completed successfully.
. 2022-09-20 16:27:18.005 Upload successful
. 2022-09-20 16:27:18.006 Transfer done: 'D:\TEST4.TXT' => '/'AAAA.BBB.CCCC.DDDDD.'/TEST4.TXT' [51]
. 2022-09-20 16:27:18.006 Copying finished: Transferred: 51, Elapsed: 0:00:00, CPS: 653/s
> 2022-09-20 16:27:18.006 Script: bye
. 2022-09-20 16:27:18.006 Script: Exit code: 0
. 2022-09-20 16:27:18.011 Disconnected from server
Albert Torres
  • 163
  • 2
  • 15
  • There's nothing wrong about the "227 Entering Passive Mode (207,192,33,30,195,108)" response. I wouldn't rule out possibility that the error message is completely misleading. + What has changed since your previous question in 2015? https://stackoverflow.com/q/30472045/850848 – Martin Prikryl Sep 21 '22 at 18:25
  • Is now required to EnableSsl. We used to download a file then we stopped but now we need to upload files same IBM mainframe. I tried the code I had before to download just adding EnableSsl but is not working anymore nor uploading files. We do not control the server side. We can see using an app what files are on the server that is why I know that WinSCP console uploads the file but not my code. – Albert Torres Sep 21 '22 at 18:57
  • The code stop at Stream ftpstream = request.GetRequestStream(); and in addition to the The remote server returned an error: 227 Entering Passive Mode (207,192,33,30,195,108) there is another: SocketException: No connection could be made because the target machine actively refused it – Albert Torres Sep 21 '22 at 19:04
  • Your original code was about upload too. And at that time it apparently have worked for you. So you believe the `EnableSsl` did break it? + When/how do you get the *"another error"*? – Martin Prikryl Sep 22 '22 at 05:12
  • I'm not sure if EnableSSL broke it because we stopped sending files a few years ago. They may have made other changes during the time we stopped sending files, now we have to do it again and this time it has to be using a secure connection. About the error, it does not show on the C# log but it's when the code stop: System.Net.WebException HResult=0x80131509 Message=The remote server returned an error: 227 Entering Passive Mode Inner Exception 1: SocketException: No connection could be made because the target machine actively refused it 207.192.50.50:50016 – Albert Torres Sep 22 '22 at 15:01
  • Are you running your C# code on the same machine and in the same local environment as WinSCP? If WinSCP can connect to the data port, why wouldn't your C# code be able to? Unless the problem is that `FtpWebRequest` connects too soon (it seems it is connecting before `STOR` command, while WinSCP connects after). – Martin Prikryl Sep 27 '22 at 05:30
  • Yes same machine – Albert Torres Sep 29 '22 at 12:39

0 Answers0