- Ankitakha
- Joined:
- Posts:
- 4
Specify record length while sftp to mainframe in .NET code
Advertisement
Hi, I am transferring file to mainframe server using WinSCP SFTP .NET code. I have to specify record length while transferring file. At my end record length is 2214 but when I am transferring file it is creating file with 100 length. I tried all transfer modes ASCII, Automatic and Binary. When I was using FTP protocol with ASCII, it used to create file with same record length of 2214. But with SFTP I am facing this issue.
Advertisement
-
martin◆
Site Admin - Joined:
- Posts:
- 41,454
- Location:
- Prague, Czechia
Re: specify record lenth while sftp to mainframe in .net code
There's no "record length" in SFTP. If your mainframe SFTP server supports that, it must be some kind of a hack or a proprietary feature. If you provide us any documentation about that, we can help you with setting it up in WinSCP. Are you able to specify the record length in any other SFTP client?
Hi, Thanks for replying. While using FTP protocol, I didn't specify any record length. At my end length of record is 2214 and while doing
session.put()
record length is same. But when I am using SFTP protocol, my line is breaking at 100 length and going to next line. Not sure if I have to set any attribute?
- Ankitakha
- Joined:
- Posts:
- 4
I see that in command we can specify it as:
But in .NET assembly code I am not getting how to specify.
sftp> ls /+lrecl=255
-
martin◆
Site Admin - Joined:
- Posts:
- 41,454
- Location:
- Prague, Czechia
You can use:
session.ListDirectory("/+lrecl=255")
Advertisement
- Guest
Hi Tried using this but getting error.
Below is the code that I used.
If I am removing
then it is creating file with data but of record length 128.
Let me know if I am doing anything wrong.
And also, even after error, it is creating file on server but with no data.Cannot overwrite remote file "FineName".$$
Press 'Delete' to delete the file and create new one instead of overwriting it.$$
Below is the code that I used.
SessionOptions sessionOptions = new SessionOptions { Protocol = Protocol.Sftp, HostName = "ServeName", UserName = "Userid", SshHostKeyFingerprint = "------------", SshPrivateKeyPath = @"----------------", }; sessionOptions.AddRawSettings("FSProtocol", "2"); sessionOptions.AddRawSettings("CacheDirectories", "0"); sessionOptions.AddRawSettings("CacheDirectoryChanges", "0"); using (Session session = new Session()) { session.Open(sessionOptions); TransferOptions transferOptions = new TransferOptions { TransferMode = TransferMode.Automatic, }; session.ListDirectory("/+lrecl=35"); session.ListDirectory("/+RECFM=FB"); session.PutFiles(sourcepath, cpedFilename, false, transferOptions).Check(); }
If I am removing
session.ListDirectory("/+lrecl=35"); session.ListDirectory("/+RECFM=FB");
Let me know if I am doing anything wrong.
-
martin◆
Site Admin - Joined:
- Posts:
- 41,454
- Location:
- Prague, Czechia
Please attach a full session log file showing the problem (using the latest version of WinSCP).
To generate the session log file, set
Session.SessionLogPath
. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.- Guest
Attached log file as private.
- Ankitakha
- Joined:
- Posts:
- 4
Hi I found the solution and its working fine for me.
I used
to create file with record length of 2214 in mainframe. I am not getting "Cannot overwrite remote file "FineName".$$" error when I used
I used
session.ListDirectory("/+recfm=fb,lrecl=2214,blksize=0,replace/");
/replace
in session.ListDirectory()
.
Advertisement
-
martin◆
Site Admin - Joined:
- Posts:
- 41,454
- Location:
- Prague, Czechia
Thanks for sharing your solution.
I have edited this into the documentation:
Can I connect to a mainframe server? (e.g. VMS, MVS, AS/400)
I have edited this into the documentation:
Can I connect to a mainframe server? (e.g. VMS, MVS, AS/400)
-
Andres Gomez
Guest
Hi, I have this problem,
Error listing directory '/+lrecl=35'.
The file path does not exist or is invalid.
// Setup session options SessionOptions sessionOptions = new SessionOptions { Protocol = Protocol.Sftp, HostName = "10.0.0.7", PortNumber = 2222, UserName = "user", Password = "password", SshHostKeyFingerprint = "ssh-rsa 2048 JEdoyPd09IwNgLHT6mnRJunJwO6GihiHhrTgq0TXrks" }; using (Session session = new Session()) { // Connect session.Open(sessionOptions); // Upload files TransferOptions transferOptions = new TransferOptions { TransferMode = TransferMode.Automatic, }; session.ListDirectory("/+lrecl=35"); session.PutFiles(@"C:\Temp\LOTE1808.035", "/public/test2/", false, transferOptions).Check(); }
-
martin◆
Site Admin
@AndresGomez: And does it work in any other SFTP client for you? For example in the command-line OpenSSH
sftp
? Show us.
Advertisement
You can post new topics in this forum