Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FTP directory created successfuly, but curl returns with error #319

Closed
pepijn-devries opened this issue Nov 5, 2023 · 3 comments
Closed

Comments

@pepijn-devries
Copy link

Currently, I'm working on some wrappers to facilitate (s)ftp access using the curl package (and httr2). I got most of it working. Creating a directory on an ftp server poses me with the following problem. Using the code below, I was able to create a directory successfully on the server, but curl stops with an error mentioning response status 257. However, this status is the server telling that it has succeeded (https://en.wikipedia.org/wiki/List_of_FTP_server_return_codes). Am I doing something wrong, or is this a bug in curl? See the reprex below using the dlptest ftp test site. Note that you may need to change the dir-name if it already exists on the server.

h <- curl::handle_setopt(curl::new_handle(), userpwd = "dlpuser:rNrKYTX9g7z3RgJRmxWuGHbeu", httpauth = 1, customrequest = "MKD mytest")
curl::curl_fetch_memory("ftp://ftp.dlptest.com/", handle = h)
#> Error in curl::curl_fetch_memory("ftp://ftp.dlptest.com/", handle = h): RETR response: 257

Created on 2023-11-05 with reprex v2.0.2

For completeness sake, my session info:

R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=Dutch_Netherlands.1252  LC_CTYPE=Dutch_Netherlands.1252    LC_MONETARY=Dutch_Netherlands.1252
[4] LC_NUMERIC=C                       LC_TIME=Dutch_Netherlands.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ftpr_0.0.1.0001 httr2_0.2.3    

loaded via a namespace (and not attached):
 [1] pillar_1.9.0    compiler_4.1.1  tools_4.1.1     digest_0.6.31   evaluate_0.21   lifecycle_1.0.3
 [7] tibble_3.2.1    pkgconfig_2.0.3 rlang_1.1.0     reprex_2.0.2    cli_3.4.1       rstudioapi_0.13
[13] curl_5.1.0      yaml_2.3.7      xfun_0.37       fastmap_1.1.0   withr_2.5.0     stringr_1.5.0  
[19] knitr_1.42      vctrs_0.6.2     fs_1.6.2        rappdirs_0.3.3  hms_1.1.2       glue_1.6.2     
[25] R6_2.5.1        processx_3.8.1  fansi_1.0.3     rmarkdown_2.22  tzdb_0.1.2      readr_2.1.3    
[31] callr_3.7.3     clipr_0.7.1     magrittr_2.0.3  ps_1.6.0        ellipsis_0.3.2  htmltools_0.5.4
[37] utf8_1.2.2      stringi_1.7.6   crayon_1.5.2
@jeroen
Copy link
Owner

jeroen commented Nov 5, 2023

I'm don't think using customrequest is really the way to create dirs. Use the CURLOPT_FTP_CREATE_MISSING_DIRS option, which I think is the same as --ftp-create-dirs in the command line.

For example this will create a new dir /test3

handle <- curl::new_handle(userpwd = "dlpuser:rNrKYTX9g7z3RgJRmxWuGHbeu", httpauth = 1, ftp_create_missing_dirs = 1L, verbose=T)
curl::curl_fetch_memory("ftp://ftp.dlptest.com/mytest3/", handle = handle)

Or if your goal is to upload a file inside a new dir, you can do that in one command like so:

curl::curl_upload('test.txt', "ftp://ftp.dlptest.com/mytest/test.txt", 
                  userpwd = "dlpuser:rNrKYTX9g7z3RgJRmxWuGHbeu", httpauth = 1, ftp_create_missing_dirs = 1L)

@pepijn-devries
Copy link
Author

Thank you for looking into this and pointing this out. The amount of options can be overwhelming sometimes ;). For creating dirs I will use your suggested approach. Just out of curiousity: why would curl or the underpinning libcurl fail on my customrequest?

@pepijn-devries
Copy link
Author

P.S., I'm asking because it would be nice to make use of other FTP features as well. For instance, the custom request FEAT does print the server features in the verbose mode, but still returns with an error:

h <- curl::handle_setopt(curl::new_handle(), userpwd = "dlpuser:rNrKYTX9g7z3RgJRmxWuGHbeu", httpauth = 1, customrequest = "FEAT", verbose = TRUE)
curl::curl_fetch_memory("ftp://ftp.dlptest.com/", handle = h)
# * Too old connection (143 seconds idle), disconnect it
# * Connection 1 seems to be dead
# * Closing connection 1
# *   Trying 44.241.66.173:21...
# * Connected to ftp.dlptest.com (44.241.66.173) port 21 (#2)
# < 220 Welcome to the DLP Test FTP Server
# > USER dlpuser
# < 331 Please specify the password.
# > PASS rNrKYTX9g7z3RgJRmxWuGHbeu
# < 230 Login successful.
# > PWD
# < 257 "/"
# * Entry path is '/'
# * Request has same path as previous transfer
# > EPSV
# * Connect data stream passively
# * ftp_perform ends with SECONDARY: 0
# < 229 Entering Extended Passive Mode (|||1041|).
# *   Trying 44.241.66.173:1041...
# * Connecting to 44.241.66.173 (44.241.66.173) port 1041
# * Connected to ftp.dlptest.com (44.241.66.173) port 21 (#2)
# > TYPE A
# < 200 Switching to ASCII mode.
# > FEAT
# < 211-Features:
# <  AUTH TLS
# <  EPRT
# <  EPSV
# <  MDTM
# <  PASV
# <  PBSZ
# <  PROT
# <  REST STREAM
# <  SIZE
# <  TVFS
# <  UTF8
# < 211 End
# * RETR response: 211
# * Remembering we are in dir ""
# * Connection #2 to host ftp.dlptest.com left intact
# Error in curl::curl_fetch_memory("ftp://ftp.dlptest.com/", handle = h) : 
#> Error in curl::curl_fetch_memory("ftp://ftp.dlptest.com/", handle = h): RETR response: 211

Created on 2023-11-06 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants