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

smb_file_mv seems not working #98

Open
DemianSteelstone opened this issue Jan 17, 2017 · 15 comments
Open

smb_file_mv seems not working #98

DemianSteelstone opened this issue Jan 17, 2017 · 15 comments
Labels

Comments

@DemianSteelstone
Copy link

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.

@sylverb
Copy link
Contributor

sylverb commented Jan 17, 2017

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.

@DemianSteelstone
Copy link
Author

DemianSteelstone commented Jan 17, 2017

I've tried different variations =)
This was last

This not working too

\\myfolder\\\\file2.txt

@DemianSteelstone
Copy link
Author

Repo with example

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

@DemianSteelstone
Copy link
Author

Hi,
Is any news?

@iam-bartl
Copy link

iam-bartl commented Jan 24, 2017

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

@jbkempf
Copy link
Contributor

jbkempf commented Feb 11, 2017

It should not be hard to fix, tbh.

DemianSteelstone referenced this issue in DemianSteelstone/libdsm Mar 7, 2017
@jbkempf
Copy link
Contributor

jbkempf commented Mar 7, 2017

Ah, interesting.

@jbkempf jbkempf added the bug label May 8, 2017
@chouquette
Copy link
Contributor

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);
    }
}

@patriknyblad
Copy link

patriknyblad commented Jul 9, 2017

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)

@chouquette
Copy link
Contributor

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

@patriknyblad
Copy link

patriknyblad commented Jul 10, 2017

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 :)

@chouquette
Copy link
Contributor

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

@patriknyblad
Copy link

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?

@DkSuperMan
Copy link

We face the same problem, how to solve?

@laoyur
Copy link

laoyur commented Jun 2, 2018

the same problem here, any news ?

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

No branches or pull requests

8 participants