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 modulefuse
for 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_other
allows 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
davfs
You would manually mount it via
mount
command:There are two reasonable way to setup it -
systemd
orfstab
. The information below is taken from davfs2 Arch wiki:For
systemd
:/etc/systemd/system/mnt-webdav-service.mount
You can create an systemd automount unit to set a timeout:
/etc/systemd/system/mnt-webdav-service.automount
For the
fstab
way it is easy if you have editedfstab
before (it behaves same as any otherfstab
entry):/etc/fstab
For webdav you can even store the credentials securely:
Create a secrets file to store credentials for a WebDAV-service using
~/.davfs2/secrets
for user, and/etc/davfs2/secrets
for 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
ZnClient
is 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
FTP
orWebDav
support 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.