none
SFTP a file from dotnet to mainframe RRS feed

  • Question

  • I want to SFTP a file from dotnet to mainframe dev region.

    Previously theyachieved this using a shell script to do so with the following command.

    sftp -P22 -b /u/path/filename remotge@host-d2

    Wednesday, October 23, 2019 4:29 PM

All replies

  • If that's known to work, then why not just use Process.Start to run that command?

    There are SFTP libraries available for C#, but that seems like a lot of extra work for nothing.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Wednesday, October 23, 2019 10:22 PM
  • Hi Tim,

    Thanks for ur time and replying me. I didnt get it. can u please elobrate

    Thursday, October 24, 2019 4:24 AM
  • If typing this command will do the job:

        sftp -P22 -b /u/path/filename remotge@host-d2

    then you can just run that command using Process.Start.

    https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?view=netframework-4.8#System_Diagnostics_Process_Start


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Thursday, October 24, 2019 4:29 AM
  • Hi how to sftp a file from dotnetcode, 

    Thank you for posting here.

    According to your problem, I have some questions to confirm with you.

    >> sftp -P22 -b /u/path/filename remotge@host-d2

    What type of language does it belong to?

    Could you provide more information about ‘mainframe dev region’? It will help us to analyze your problem.

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 24, 2019 8:05 AM
    Moderator
  • Im trying to develop the code in C#.

    Previously it worked fine when FTPed the command in Shell script.

    sftp -P22 -b /u/path/filename remotge@host-d2

    Can you please let me know what information do u require regarding the mainframe Dev region

    Inside Mainframe we are placing the file in the dev region. No specific path. So how can we achieve the same through C# Code

    Thursday, October 24, 2019 12:03 PM
  • > Inside Mainframe we are placing the file in the dev region.  No specific path.

    The term "dev region" doesn't mean anything to us.  However, every sftp login starts in a default directory, and the command line you posted would transfer the file to the default directory.  Xingyu doesn't really need to know anything about the mainframe; he's just stalling for time hoping you provide more information.

    The "sftp" command you posted is for a Unix-based system.  Are you running your C# code on a Unix system?  If so, then my advice to use Process.Start is still the best advice.  Don't reinvent the wheel.  You already have a tool that works.

    On Windows, there are several packages that offer an sftp command line, including Putty and WinSCP.  Both of those could be used.  With those, you could still use Process.System.

    If you still insist on wasting your time by coding this in C#, the SSH.NET package includes an SFTP client for C#.



    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Friday, October 25, 2019 7:22 AM