[SOLVED] Writing an SFTP client
[SOLVED] Writing an SFTP client
We need to develop an SFTP client as part of a sales order processing system. When I first found PureBasic last year, the first thing I noticed was that it already provides FTP, straight out of the box. Within about 30 minutes, I had written an ftp transfer routine . Due to the fact that this new requirement is for an invoice data transfer, it falls to me to provide (or develop) an SFTP solution. Is this possible to do in PB?
I have seen something on a website called Chilkat with examples of PB code and I'm not sure if others are aware of this.
I have seen something on a website called Chilkat with examples of PB code and I'm not sure if others are aware of this.
Last edited by Oso on Mon Jan 30, 2023 7:37 pm, edited 1 time in total.
Re: Writing an SFTP client
Hi
I use Chillkat often and it works well with PB. So it should be fairly simple to create an SFTP app with PB and Chillkat.
Simon
I use Chillkat often and it works well with PB. So it should be fairly simple to create an SFTP app with PB and Chillkat.
Simon
Simon White
dCipher Computing
dCipher Computing
Re: Writing an SFTP client
Thanks for the reply, Simon. Do they provide all those modules shown on their website as a single package? It wasn't entirely clear to me how to choose the required module.
Re: Writing an SFTP client
You don't need to by something.
It is possible with libcurl.
For this you need an external libcurl.dll (or compile your own static lib) which includes sftp.
And my libcurl.pbi.
Then you can use:
https://curl.se/libcurl/c/sftpget.html
https://curl.se/libcurl/c/sftpuploadresume.html
My libcurl.pbi is here:
viewtopic.php?t=80118
In the libcurl.dll, which is in my zip file, sftp is included.
you need to set
before your IncludeFile.
And copy the corresponding dll to your file directory.
(I always set the option 'create temporary executable in the sourcecode directory' in compiler options)
It is possible with libcurl.
For this you need an external libcurl.dll (or compile your own static lib) which includes sftp.
And my libcurl.pbi.
Then you can use:
https://curl.se/libcurl/c/sftpget.html
https://curl.se/libcurl/c/sftpuploadresume.html
My libcurl.pbi is here:
viewtopic.php?t=80118
In the libcurl.dll, which is in my zip file, sftp is included.
you need to set
Code: Select all
#LibCurl_ExternalDLL = #True
And copy the corresponding dll to your file directory.
(I always set the option 'create temporary executable in the sourcecode directory' in compiler options)
--- Info ---
Version: 7.86.0
Host: i686-w64-mingw32
SSL: OpenSSL/3.0.7 (Schannel)
Libz: 1.2.13
libSSH: libssh2/1.10.0
Protocols:
dict
file
ftp
ftps
gopher
gophers
http
https
imap
imaps
ldap
ldaps
mqtt
pop3
pop3s
rtsp
scp
sftp
smb
smbs
smtp
smtps
telnet
tftp
ws
wss
--- Info ---
Re: Writing an SFTP client
This is great Infratec, thanks very much indeed. The two links that you included for the C code at curl.se/libcurl/c... — I assume this is just for reference? In the C code is #include <curl/curl.h> so I'm guessing your libcurl.pbi is an equivalent of that C header file. Am I understanding it correctly?infratec wrote: ↑Wed Jan 25, 2023 11:29 pm It is possible with libcurl. For this you need an external libcurl.dll (or compile your own static lib) which includes sftp. And my libcurl.pbi.
Then you can use: https://curl.se/libcurl/c/sftpget.html https://curl.se/libcurl/c/sftpuploadresume.html
My libcurl.pbi is here: viewtopic.php?t=80118 In the libcurl.dll, which is in my zip file, sftp is included.
Re: Writing an SFTP client
Just now I added an example for SFTP in my ZIP file.
You need also the modified LibCurl.pbi
You can (more or less) directly convert the C examples. The calls to libcurl are nearly identical.
You need also the modified LibCurl.pbi
You can (more or less) directly convert the C examples. The calls to libcurl are nearly identical.
Re: Writing an SFTP client
Thanks Infratec, I've just been looking at it the SFTP. The rebex.net ftp test is useful, that saves the need to set up an sftp server on another machine.
Incidentally, where is the function that determines whether we are using 'get' or 'put'? I looked at your two ftps examples earlier and I see that one is sending, the other receiving, but I couldn't see where it sets that mode.
Incidentally, where is the function that determines whether we are using 'get' or 'put'? I looked at your two ftps examples earlier and I see that one is sending, the other receiving, but I couldn't see where it sets that mode.
Re: Writing an SFTP client
curl_easy_setopt(curlhandle, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curlhandle, CURLOPT_URL, remotepath);
curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc);
curl_easy_setopt(curlhandle, CURLOPT_READDATA, f);
Re: Writing an SFTP client
Added examples:
SFTP_upload.pb
SFTP_uploadresume.pb
SFTP_upload.pb
SFTP_uploadresume.pb
Re: Writing an SFTP client
Yes all the modules are included in the download.
Simon
Simon
Simon White
dCipher Computing
dCipher Computing
Re: Writing an SFTP client
They work very well indeed Thank you for adding these Infratec. I tested using a 13MB file which was transferred perfectly. I will continue tomorrow, as it's late here now. I looked at 'resume' and I see that it has the capability to send from the last point onwards. Thanks again for doing this. I will think about it further and have some more ideas.