How do we send or upload a data file to a server on Pharo. I saw some example of sending file from a directory on the machine. It works fine.
ZnClient new
url: MyUrl;
uploadEntityfrom: FileLocator home /Path to the file;
put
In my case I don't want to send/upload file downloaded on a machine but instead I want to send/upload a file hosted somewhere or data I retrieved over the network and send it attached to another server. How can we do that ?
Based on your previous questions I presume you are using linux. The issue here is not within Smalltak/Pharo, but the network mapping.
FTP
If you want to have a ftp, don't forget it is sending password in plaintext, set-up it a way you can mount it. There are probably plenty of ways to do this but you can try using
curlftpfs. You need kernel modulefusefor that, make sure you have it loaded. If it is not loaded you can do so viamodprobe fuse.The usage would be:
where you fill username/password. The option
allow_otherallows other users at the system to use your mount. (for more details you can see arch wiki and its curlftpfs)Webdav
For webdav I would use the same approach, this time using
davfsYou would manually mount it via
mountcommand:There are two reasonable way to setup it -
systemdorfstab. The information below is taken from davfs2 Arch wiki:For
systemd:/etc/systemd/system/mnt-webdav-service.mountYou can create an systemd automount unit to set a timeout:
/etc/systemd/system/mnt-webdav-service.automountFor the
fstabway it is easy if you have editedfstabbefore (it behaves same as any otherfstabentry):/etc/fstabFor webdav you can even store the credentials securely:
Create a secrets file to store credentials for a WebDAV-service using
~/.davfs2/secretsfor user, and/etc/davfs2/secretsfor root:Make sure the secrets file contains the correct permissions, for root mounting:
And for user mounting:
Back to your Pharo/Smalltalk code:
I presume you read the above and have either /mnt/ftp or /mnt/webdav mounted.
For e.g. ftp your code would simply take from the mounted directory:
Edit Bassed on the comments.
The issue is that the configuration of the
ZnClientis in the Pharo itself and the json file is also generated there.One quick and dirty solution - would be to use above mentined with a shell command:
With ftp for example:
Other approach is more sensible. Is to use Pharo
FTPorWebDavsupport via FileSystemNetwork.To load ftp only:
to load Webdav only:
To get everything including tests:
With that you should be able to get a file for example for
ftp:Then your upload via (ftp) would look like this:
The Webdav would be similar.