Author Topic: Suggestions for an SFTP process  (Read 9302 times)

MW4

  • Full Member
  • ***
  • Posts: 176
Suggestions for an SFTP process
« on: April 17, 2014, 10:39:16 am »
I have a process that I need to set up that will do the following:
  1.  Connect with an SFTP server
  2.  Download some specifically named files to a local folder
  3.  Decrypt all of the files in that folder.
  4.  Them move them to the specific folders that they will need to reside in for use.

We have used Cleopatra on a singular file basis and the connect and decrypt works fine, we just need to automate it into a scheduler job.
Any help in pointing me in the right direction would be fantastic.
If there is a better solution than Cleopatra, I'm all ears.

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Suggestions for an SFTP process
« Reply #1 on: April 17, 2014, 10:47:10 am »
Deana F.
Technical Support
Wilson WindowWare Inc.

MW4

  • Full Member
  • ***
  • Posts: 176
Re: Suggestions for an SFTP process
« Reply #2 on: April 24, 2014, 03:21:44 pm »
ok, I hit a snag with the script.

ObjectClrOption ( 'use', 'WinSCP, Version=1.1.5.4214, Culture=neutral' )

that is the version of the dot.net dll that I downloaded today



Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Suggestions for an SFTP process
« Reply #3 on: April 24, 2014, 04:55:54 pm »
You might want to make sure your are using the correct assembly directory path in the APPBASE statement, before calling the USE. Also click on the More Error Info button and post the resulting extended error information.
Deana F.
Technical Support
Wilson WindowWare Inc.

MW4

  • Full Member
  • ***
  • Posts: 176
Re: Suggestions for an SFTP process
« Reply #4 on: June 26, 2014, 12:39:42 pm »
More error info

MW4

  • Full Member
  • ***
  • Posts: 176
Re: Suggestions for an SFTP process
« Reply #5 on: June 26, 2014, 12:45:44 pm »
Currently I can pull the files manually until I can get the WinSCP part working.

So...

How about the Decrypt part, what is suggested for that?

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Suggestions for an SFTP process
« Reply #6 on: June 26, 2014, 12:52:09 pm »
Did you check the AppBase folder is correctly pointing the WinSCP directory?

What is the name of the dll in the WinSCP directory?



Deana F.
Technical Support
Wilson WindowWare Inc.

MW4

  • Full Member
  • ***
  • Posts: 176
Re: Suggestions for an SFTP process
« Reply #7 on: June 26, 2014, 02:06:07 pm »
Yes, pointing correctly

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Suggestions for an SFTP process
« Reply #8 on: June 26, 2014, 02:46:01 pm »
The dll name is WinSCPnet.dll therefore your script should read:

Code: Winbatch
ObjectClrOption ( 'use', 'WinSCPnet, Version=1.1.5.4214, Culture=neutral' )
 
Deana F.
Technical Support
Wilson WindowWare Inc.

richardh

  • Jr. Member
  • **
  • Posts: 54
Re: Suggestions for an SFTP process
« Reply #9 on: July 01, 2014, 05:12:18 am »
I will definitely be using this example for my needs.
Thanks Deana  :)

MW4

  • Full Member
  • ***
  • Posts: 176
Re: Suggestions for an SFTP process
« Reply #10 on: July 11, 2014, 12:33:16 pm »
Getting these two errors in the attachments...
looks like WinSCPnet is not coming through (from trace below)

ObjectClrOption ( 'use', 'WinSCPnet, Version=1.1.5.4214, Culture=neutral' )

mscorlib=Could not load file or assembly 'WinSCP, Version=1.1.5.4214, Culture=neutral' or one of its dependencies. The module was expected to contain an assembly manifest.


td

  • Tech Support
  • *****
  • Posts: 3455
    • WinBatch
Re: Suggestions for an SFTP process
« Reply #11 on: July 11, 2014, 01:08:03 pm »
The "mscorlib=Could..." error is just a legacy error living on in the ini file.  The second error is relevant and indicates that you are either using an invalid or incorrectly formated thumb print. You need to verify that you have the correct hash and that it is in the format expected by the SshHostKeyFingerprint method.  Also, you need to check that all the other parameter option you are assigning are correct as any of these could might be the source of the error.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

MW4

  • Full Member
  • ***
  • Posts: 176
Re: Suggestions for an SFTP process
« Reply #12 on: July 11, 2014, 01:20:44 pm »
I had mis matched Program versions and the .net dll
Fixed that.
I also had a bad path...fixed and works!!!!!


Woo HOO!!!

Thank You  Deana!!


MW4

  • Full Member
  • ***
  • Posts: 176
Re: Suggestions for an SFTP process
« Reply #13 on: July 11, 2014, 01:37:05 pm »
Now as a finishing piece...

what's the command to delete that file from the FTP server after a download?


second finishing piece....

Files are in that folder as this:
/outbound/NNA2FAIR_INVOC.2014_07_10_0132.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0145.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0156.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0159.TXT.PGP

I need to pull many files that start with /outbound/NNA2FAIR_INVOC <WILDCARD>
and save them to my local dir using the whole filename.

The folder contains files that are not mine so I don't want to sync the entire directory.

Using the code like it is, how would you accomplish that?



td

  • Tech Support
  • *****
  • Posts: 3455
    • WinBatch
Re: Suggestions for an SFTP process
« Reply #14 on: July 11, 2014, 02:02:05 pm »
The online documentation for the WinSCP assembly is quit good.  I recommend you check it out.  It clearly states that the 'GetFiles' method accepts wildcards so if your files can be identified by name, you could construct a wildcard file name the matches the files you want to retrieve.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

MW4

  • Full Member
  • ***
  • Posts: 176
Re: Suggestions for an SFTP process
« Reply #15 on: July 11, 2014, 02:10:12 pm »
I just looked through that and it works quite well.

I got the wildcard and am about to test the delete.

Thanks again for the help

MW4

  • Full Member
  • ***
  • Posts: 176
Re: Suggestions for an SFTP process
« Reply #16 on: July 11, 2014, 03:29:29 pm »
bFalse = ObjectType( 'BOOL', 1 )

1 sets delete



transferResult = objSession.GetFiles( '/outbound/NNA2FAIR*', 'c:\tempy\', bFalse, objTransferOptions) 

* = standard wildcard

MW4

  • Full Member
  • ***
  • Posts: 176
Re: Suggestions for an SFTP process
« Reply #17 on: September 22, 2014, 10:18:30 am »
One further question on this topic...

What is the easiest way to query up the "oldest" file and then just download that one... IE:

from these files in the directory
/outbound/NNA2FAIR_INVOC.2014_07_10_0132.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0145.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0156.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0159.TXT.PGP


/outbound/NNA2FAIR_INVOC.2014_07_10_0132.TXT.PGP  would be the oldest

td

  • Tech Support
  • *****
  • Posts: 3455
    • WinBatch
Re: Suggestions for an SFTP process
« Reply #18 on: September 22, 2014, 02:21:10 pm »
If you can assume that the oldest last write time for a file also means that it is the oldest file then the 'GetFileInfo' method of the Session object looks interesting.

The method can be found here:

http://winscp.net/eng/docs/library_session_getfileinfo#parameters

and the method's return class here:

http://winscp.net/eng/docs/library_remotefileinfo

The 'ListDirectory' method might be an even better choice:

http://winscp.net/eng/docs/library_session_listdirectory

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade