Recent

Author Topic: sFTP session example  (Read 18297 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
sFTP session example
« on: April 14, 2015, 01:52:16 pm »
Hello guys, who explained to me how to make an ftp session with lazarus to send and receive a file? Possibly with synapse
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: sFTP session example
« Reply #1 on: April 16, 2015, 03:22:44 pm »
Guys, really no one knows how to do? I found this example, but it should work only with Windows. I need to succeed even with linux. Ideas?

http://synapse.ararat.cz/files/contrib/sftp.zip
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: sFTP session example
« Reply #2 on: April 16, 2015, 03:46:38 pm »
« Last Edit: April 16, 2015, 03:55:52 pm by ChrisF »

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: sFTP session example
« Reply #3 on: April 16, 2015, 04:28:00 pm »
The BigChimp's answer is FTP solution, my problem is sFTP.

Secure File Transfert Protocol
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: sFTP session example
« Reply #4 on: April 16, 2015, 04:50:48 pm »
Sorry, my mistake.  I've only read your  topic message, not the title...

... how to make an ftp session with lazarus to send and receive a file...

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: sFTP session example
« Reply #5 on: April 16, 2015, 04:51:36 pm »
Guys, really no one knows how to do? I found this example, but it should work only with Windows. I need to succeed even with linux. Ideas?
Why should that only work on Windows? CryptLib is also available on Linux.

What doesn't work on Linux in SimpleSFTP.pas (after changing winsock to synsock, which you should do with all the synapse examples)?

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: sFTP session example
« Reply #6 on: April 16, 2015, 04:59:31 pm »
@rvk

There are -at least- a few Windows API calls in SimpleSFTP.pas.

Though I've not checked if there are a lots of (it's quite possible there are only very few of them).

Code: [Select]
CreateFile
CloseHandle
Windows.GetFileTime
Windows.SetFileTime
...
« Last Edit: April 16, 2015, 05:02:39 pm by ChrisF »

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: sFTP session example
« Reply #7 on: April 16, 2015, 05:10:59 pm »
There are -at least- a few Windows API calls in SimpleSFTP.pas.
Woops, yeah. I see.
That's gonna be a challenge to convert to Linux-compatibility  :)
But it should be possible (although not for me as I'm not a Linux guy).

I haven't found any examples for sFTP which are Linux-ready for Synapse.

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: sFTP session example
« Reply #8 on: April 16, 2015, 05:30:23 pm »
That's gonna be a challenge to convert to Linux-compatibility  :)
But it should be possible (although not for me as I'm not a Linux guy).

I also guess it's quite possible to port it to Linux (but I'm not a Linux code neither).

Apparently, after a quick test (Delphi 7 with TestSFTP demo), the Windows unit is needed only for:

- Copy Memory. A simple "wrapper" for it is simple:
Code: [Select]
procedure CopyMemory(Destination:PVOID; Source:pointer; Length:DWORD);
begin
  Move(Source^, Destination^, Length);
end;

- TSimpleSFTP.GetLocalFileTimes and TSimpleSFTP.SetLocalFileTimes: those ones are apparently the only methods using directly the Windows API. So, I guess they could be rewritten from the scratch for Linux.


*** EDIT ***

I've used winsock for my quick test. So, it's not impossible there are a few additional issues with it.
« Last Edit: April 16, 2015, 05:41:54 pm by ChrisF »

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: sFTP session example
« Reply #9 on: April 18, 2015, 05:47:36 pm »
I also guess it's quite possible to port it to Linux (but I'm not a Linux code neither).
Well... With my zero knowledge of Linux-GUI/desktop programming I just went for it :)
(I only have experience with Linux servers at the command line  %))

On the internet I only found commercial solutions for sFTP on Linux. So creating a working SimpleSFTP.pas could be interesting for more people.

Adding a function CopyMemory, changing winsock to synsock and removing Windows I only had to IFDEF out the GetLocalFileTimes and SetLocalFileTimes functions. I think they are only used in (and after) the real getting and putting of files. For me it was only to test if I got this SimpleSFTP.pas running and connected under Linux. And it worked. I had a hell of a time installing CryptLib correctly (the beta 343 version didn't work) but finally cl342 did work.

Here is the result connecting from Linux to a SFTP_2000.exe server (I got from here) running on a Windows 7 machine. The adjusted SimpleSFTP.pas is also attached.

As you can see it connects correctly and I get the directory-result from the server. The factual transference of files doesn't work (yet). You'll get some errors. But it shows that using this SimpleSFTP.pas isn't as hard as we initially thought.

@xinyiman, if you interested in help perfecting this SimpleSFTP.pas, let us know.

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: sFTP session example
« Reply #10 on: May 14, 2015, 08:47:10 pm »
Thank you for your advice. I intend to fix it. Only where can I download cryptlib for Ubuntu? Does anyone know?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: sFTP session example
« Reply #11 on: May 14, 2015, 08:57:20 pm »
Lazarus Ver 2.2.6 FPC Ver 3.2.2
Windows 10 Pro 64-bit

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: sFTP session example
« Reply #12 on: May 20, 2015, 10:40:53 am »
Some progress has been made. but I still need help.
As a prerequisite need to have cryptlib installed. Debian derived just type

sudo apt-get install libcrypt *

Then, download the attached file and try to compile it. You will see that will tell you that there are problems with the LCL. Ideas?

PS: remember to give the path of the synapse source does not work otherwise.


Attachments: http://www.lazaruspascal.it/index.php?action=dlattach;topic=1539.0;attach=429
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: sFTP session example
« Reply #13 on: May 20, 2015, 10:51:26 am »
Then, download the attached file and try to compile it. You will see that will tell you that there are problems with the LCL. Ideas?
I (we) don't have access to the Italian Lazarus-forum, so you might want to post your attachment here.

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: sFTP session example
« Reply #14 on: May 20, 2015, 11:00:22 am »
Sorry
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018