libdsm icon indicating copy to clipboard operation
libdsm copied to clipboard

smb_file_mv seems not working

Open DemianSteelstone opened this issue 8 years ago • 15 comments

Hi, I'm trying to use your lib in my ios project But have some troubles with move operation.

My code example:

smb_session *session = smb_session_new();
smb_session_connect(session, hostName, addr.s_addr, SMB_TRANSPORT_TCP);
smb_session_set_creds(session, hostName, userName, password);

smb_tid treeID;
NSString *shareName = [self.path shareName];
const char *shareCString = [shareName cStringUsingEncoding:NSUTF8StringEncoding];
smb_tree_connect(self.smbSession, shareCString, &treeID);

NSString *srcPath = [self.path formattedFilePath];  // path like "\\myfolder\\\\file.txt"
NSString *dstPath = [[dst stringByTrimmingCharactersInSet:trimSet] slashesEscape]; // "\\mysharename\\\\myfolder\\\\file2.txt"
    
int result = smb_file_mv(self.smbSession,self.treeID,srcPath.UTF8String,dstPath.UTF8String);

and now I got "result == -3"

Maybe I'm doing something wrong?

Other operations like create folder or remove works perfectly.

DemianSteelstone avatar Jan 17 '17 07:01 DemianSteelstone

Hi, "\mysharename\\myfolder\\file2.txt" -> Why are you having a share name in the path ? SMB is not allowing files to be moved from a share to another share so you should't have it in the dest path.

sylverb avatar Jan 17 '17 07:01 sylverb

I've tried different variations =) This was last

This not working too

\\myfolder\\\\file2.txt

DemianSteelstone avatar Jan 17 '17 07:01 DemianSteelstone

Repo with example

https://github.com/DemianSteelstone/SMBTestProj.git

DemianSteelstone avatar Jan 18 '17 07:01 DemianSteelstone

Hi, Is any news?

DemianSteelstone avatar Jan 20 '17 06:01 DemianSteelstone

Hi, have you solved this issue? We face the same problem :(

iam-bartl avatar Jan 24 '17 06:01 iam-bartl

It should not be hard to fix, tbh.

jbkempf avatar Feb 11 '17 15:02 jbkempf

Ah, interesting.

jbkempf avatar Mar 07 '17 09:03 jbkempf

I fail to reproduce the issue.

For future reference here is the sample I used

#include <bdsm/netbios_ns.h>
#include <bdsm/netbios_defs.h>
#include <bdsm/smb_session.h>
#include <bdsm/smb_types.h>
#include <bdsm/smb_share.h>

#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define FOLDER "\\madamemichu\\Documents\\SharedLoutre\\"

int main()
{
    struct sockaddr_in addr;
    const char* host = "hydromel";
    const char* user = "MadameMichu";
    const char* pass = "loutre";
         

    netbios_ns* ns = netbios_ns_new();
    if (netbios_ns_resolve(ns, host, NETBIOS_FILESERVER, &addr.sin_addr.s_addr) != 0)
    {
        printf("Failed to resolve host\n");
        exit(2);
    }

    smb_session *session = smb_session_new();
    if (smb_session_connect(session, host, addr.sin_addr.s_addr, SMB_TRANSPORT_TCP) != 0)
    {
        printf("Failed to create session\n");
        exit(3);
    }
                 
    smb_session_set_creds(session, host, user, pass);
    if (smb_session_login(session) != 0)
    {
        printf("failed to login\n");
        exit(1);
    }

    smb_tid tid;
    if ( smb_tree_connect(session, "Users", &tid) != 0)
    {
        printf("failed to list folder\n");
        exit(1);
    }

    if (smb_file_mv(session, tid, FOLDER "loutre.txt", FOLDER "newLoutre.txt" ) != 0)
    {
        printf("Failed to move file\n");
        exit(123);
    }
}

chouquette avatar Jul 07 '17 12:07 chouquette

I have not tried this myself but the examples above as well as the linked project are using double backslashes in the file path like if referencing another host(?) in the middle of the path string.

Typically an SMB path when connecting using the explorer in Windows looks like this: "\\hostname\share\folder\"

(edited with correct number of slashes)

patriknyblad avatar Jul 09 '17 14:07 patriknyblad

This is because you have to inhibit the '' special meaning in most languages using another backslash. In the resulting string, there will be only 1 backslash

chouquette avatar Jul 10 '17 08:07 chouquette

Yes I understand that you need to escape the backslash but what I do not understand is why there are more backslashes in the middle of the path than at the beginning. Also my example in the comment above was autocorrected by my phone.

Windows share example again: "\\hostname\share\folder"

The original question by DemianSteelstone writes his path like this after escaping: "\share\\folder\\file.ext"

The comment just above my first comment (the one made by you @chouquette) writes the file path as I would expect it to be written: "folder\file.ext" (host name specified in other variable and connected to using a separate API call)

What I am trying to say is that your (chouquette) example looks correct while the other examples all have the same error(?) in common.

I will try this lib on iOS after vacation because it looks fun. If I am on the wrong track, any pointers would be appreciated :)

patriknyblad avatar Jul 10 '17 08:07 patriknyblad

Oops, sorry about the confusion then :) You're making a good point about the path being invalid, however I don't understand how the linked patch would change their handling... I guess I might have to find myself a SMB protocol doc

chouquette avatar Jul 10 '17 15:07 chouquette

I know nothing about the smb protocol and I think you did a fine job with this lib. Was just worried when I saw the bug right after I made up my mind on using this lib and thought that a feature like move must be working and cannot really have gone unnoticed.

A newbie question, why are the paths specified using back slashes instead of forward slashes like in Linux or MacOS?

patriknyblad avatar Jul 10 '17 16:07 patriknyblad

We face the same problem, how to solve?

DkSuperMan avatar Jan 27 '18 16:01 DkSuperMan

the same problem here, any news ?

laoyur avatar Jun 02 '18 08:06 laoyur