I am working on an API that needs to download a file from server A and upload it to server B in the same network. It's for internal use. Each of the files will have multiple versions and will need to be uploaded to server B multiple times and all the versions of the same file will share the same file name. This is my first time dealing with file manipulation so please bare with me if my question sounds ignorant. Can I use HttpClient.PostAsync for the uploading part in this effort? Or can I just use Stream.CopyToAsync if it's ok to just copy over? Thanks!
-
Did you try them? Did they both work? What issue did you face with your implementation?mason– mason2020-09-23 14:58:11 +00:00Commented Sep 23, 2020 at 14:58
-
Please provide some code of what you are trying to doOleksandr– Oleksandr2020-09-23 15:24:48 +00:00Commented Sep 23, 2020 at 15:24
-
I tried CopyToAsync and it copied the file but it's all happening on my local machine.SamulP– SamulP2020-09-23 15:28:48 +00:00Commented Sep 23, 2020 at 15:28
Add a comment
|
1 Answer
- Stream.CopyToAsync copies stream from one to another inside memory of same server.
- In your case, you can use HttpClient.PostAsync, but one the other server there should be some api to receive the stream content and save to disk.
5 Comments
SamulP
Thank you for explaining this. The problem with the 2nd option is the destination server is used purely for storage so there can't be an API there to receive the content. I'd think this is a very common case and I must have been following the wrong direction.
Rajdeep D
Else you can use FileZilla to transfer file
SamulP
Thanks! FileZilla seems to be a nice tool but the request is to have this file transfer done programmatically.
Rajdeep D
You can use powershell script.
Foreach-Object { copy-item -ServerAPath $_.fullname -Destination \\ServerB\shared\Folder }SamulP
Thank you! I'll give that a try!